<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/layui/css/style.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../layuiadmin/style/admin.css?v=${.Config.basic.version}" media="all">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/metroStyle.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="../plugins/zTree/css/metroStyle/ext.css?v=${.Config.basic.version}">
    <link rel="stylesheet" href="//at.alicdn.com/t/c/font_3564966_a6tt4yhnzge.css" media="all">
    <link rel="stylesheet" href="../plugins/toastr/toastr.min.css?v=${.Config.basic.version}">
    <style>

        .layui-form-item .layui-input-inline {
            float: left;
            width: 150px;
            margin-right: 10px;
        }
        .layui-form-item {
            margin-top: 5px;
            margin-bottom: 10px;
        }

        .layui-btn + .layui-btn {
            margin-left: 5px;
        }
        .layui-btn-xs {
            height: 18px;
            line-height: 18px;
            padding: 0 5px;
            font-size: 11px;
        }

        .layui-form-label-lg {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 130px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }
        .layui-form-select dl {
            max-height: 150px;
        }

        /*.layui-form-item .layui-input[readonly] {*/
        /*    background-color: #0a1434;*/
        /*    color: #a6b8d5;*/
        /*    border: none;*/
        /*    border-top-color: currentcolor;*/
        /*    border-right-color: currentcolor;*/
        /*    border-bottom-color: currentcolor;*/
        /*    border-left-color: currentcolor;*/
        /*}*/
        
    </style>

    <style>
        /* .layui-table-view .layui-table td, .layui-table-view .layui-table th {
            padding: 5px 0;
            border-top: 1px solid #404453;
            border-left: 1px solid #404453;
            border-bottom: 1px solid #404453;
            border-right: 1px solid #404453;
        } */
        .layui-table-cell {
            line-height: 20px !important;
            vertical-align: middle;
            height: auto;
            overflow: visible;
            text-overflow: inherit;
            white-space: normal;
        }
        .layui-table-view .layui-table[lay-size="sm"] .layui-table-cell {
            line-height: 20px !important;
            vertical-align: middle;
            height: auto;
            overflow: visible;
            text-overflow: inherit;
            white-space: normal;
        }
    </style>

</head>

<body class="layui-layout-body">
<div class="layui-fluid">
    <div style="display: flex;">
        <div style="width: 250px;">
            <div class="layui-card tree-div">

                <div class="">
                    <div class=" " >
                        <ul id="treeDemo" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div style="width: calc(100% - 250px);float: right; " >
            <div class="layui-card">
                <div class="layui-card-body">
                    <form class="layui-form" lay-filter="form_search" id="form_search" action="">
                        <div class="layui-form-item">


                            <div class="layui-inline">
                                <!--<label class="layui-form-label auto-size-label"></label>-->
                                <div class="layui-input-inline">
                                    <input type="text" name="key" placeholder="请输入关键字" lay-verify="" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="" lay-filter="btn_search"><i class="layui-icon layui-icon-search"></i>查询</button>
                                <!--<button type="button" class="layui-btn layui-btn-normal layui-btn-sm action-export layui-hide" lay-submit="" lay-filter="btn_search"><i class="fa fa-file-excel-o"></i> 导出</button>-->
                            </div>

                            <div class="layui-inline fr">
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal action-sync_ext_para layui-hide" lay-submit="" lay-filter="btn_sync_name"><i class="layui-icon layui-icon-release"></i>同步名称</button>
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal action-sync_ext_para layui-hide" lay-submit="" lay-filter="btn_sync_limit"><i class="layui-icon layui-icon-release"></i>限制子设备数目</button>
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal action-update layui-hide" lay-submit="" lay-filter="btn_update_device"><i class="layui-icon layui-icon-release"></i>更新勾选终端</button>
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-normal action-update layui-hide" lay-submit="" lay-filter="btn_update_feednode"><i class="layui-icon layui-icon-release"></i>更新勾选饲喂器</button>
                            </div>

                        </div>
                    </form>

                    <table class="layui-hide" id="table" lay-filter="table"></table>
                    <script type="text/html" id="table_toolbar">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-sm layui-btn-normal  action-edit layui-hide" lay-event="addDevice">增加</button>
                        </div>
                    </script>




                </div>
            </div>
        </div>
    </div>


</div>

<script src="../plugins/layui/layui.js"></script>
<script src="../plugins/layui/xm-select-v1.2.4.js"></script>
<script src="../plugins/jquery/jquery-3.6.0.js?v=${.Config.basic.version}"></script>
<script src="../plugins/zTree/js/jquery.ztree.core.min.js?v=${.Config.basic.version}"></script>
<script src="../plugins/zTree/js/jquery.ztree.excheck.js?v=${.Config.basic.version}"></script>
<script src="../plugins/zTree/js/jquery.ztree.exedit.js?v=${.Config.basic.version}"></script>
<script src="../plugins/jquery.slimscroll.min.js"></script>
<script src="../plugins/toastr/toastr.min.js"></script>
<script src="../js/utils.js"></script>
<script src="../js/verify.js"></script>
<script src="../js/func.js?v=${.Config.basic.version}"></script>
<script>
    var zTree=null;
    var table=null;
    var form=null;
    var Table=null;
    var lay_index=null;
    var curAddr=null;
    var laydate = null;

    var transfer=null;
    var userItems=[];
    var device_define=[];

    var czqPara=null;//终端参数
    var czqState=null;

    //时间点+曲线拷贝
    var has_copy=false;
    var copy_OutDay=[];
    var copy_OutMax=[];
    var copy_StartT=[];
    var copy_EndT=[];
    var copy_OutT=[];


    var users = [];
    var selectUser = null;
    var allData=[];

    var token = window.localStorage.getItem("token");
    var user_info=JSON.parse(window.localStorage.getItem("user_info"));
    var is_admin = user_info.is_admin;
    var func_url="${.func_url}";
    var actions=[];
    var token = window.localStorage.getItem("token");
    token = 'Bearer ' + token;

    var selectedTreeNode=null;
    var select_node_idx=null;
    var select_device=null;
    var device_type = null;

    var tree_setting = {
        async: {
            enable: true,
            type: "get",
            headers:{'Authorization':token},
            url: '../Api/Topo/GetAsync',
            autoParam:["id", "type"], //节点参数提交给后台,这里提交id和类型到后台
            otherParam:{"device_type":"DMXFGW"}, //静态参数
            dataFilter: filter,
        },
        view: {
            dblClickExpand: false,
            fontCss: getFont,
            nameIsHTML: true,
        },
        callback: {
            onClick: treeOnClick,
        }
    };
    function filter(treeId, parentNode, res) {
        console.info(res)
        if (!res.data) return null;
        var nodes = res.data;
        nodes=setDataIcon(nodes);
        return nodes;
    }
    var tree_setting1 = {
        view: {
            dblClickExpand: false,
            fontCss: getFont,
            nameIsHTML: true,
        },
        callback: {
            onClick: treeOnClick1,
        }
    };

    layui.config({
        base: '../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','layer','form', 'table','transfer','laydate'],function(){
        form = layui.form;
        table = layui.table;
        transfer = layui.transfer;
        laydate = layui.laydate;
        toastr.options = {
            "closeButton": false, //是否显示关闭按钮
            "debug": false, //是否使用debug模式
            "positionClass": "toast-top-center",//弹出窗的位置
            "showDuration": "300",//显示的动画时间
            "hideDuration": "1000",//消失的动画时间
            "timeOut": "2000", //展现时间
            "extendedTimeOut": "1000",//加长展示时间
            "showEasing": "swing",//显示时的动画缓冲方式
            "hideEasing": "linear",//消失时的动画缓冲方式
            "showMethod": "fadeIn",//显示时的动画方式
            "hideMethod": "fadeOut" //消失时的动画方式
        };
        form.verify({
            verify_ip:verify_ip,
            addr: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(/^\d+\d+\d$/.test(value)==false){
                    return '必须是10进制数值';
                }
                if(value.length!==10){
                    return '长度必须是10';
                }
            },
            percent: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(/^([0-9]{1,2}|100)$/.test(value)==false){
                    return '0-100之间的正整数';
                }
            },
        });



        $.ajax({
            type: 'GET',
            url: '../Api/User/Actions',
            data: {func_url:func_url},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (data) {
                console.info(data)
                actions=data.data;
                for(var i=0;i<actions.length;i++){
                    $('.action-'+actions[i].action_id).removeClass("layui-hide");
                }
                //initTable();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载操作信息失败');
            }
        });

        $.ajax({
            type: 'GET',
            url: '../Api/DeviceDefine',
            data: {},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                console.info(res)
                if(res.code>=0){
                    device_define = res.data;
                    renderSelect();
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载设备类型失败');
            }
        });

        laydate.render({
            elem: '#StartT'
            ,theme: '#133678'
            ,type: 'time'
            ,format: 'HH:mm'
            ,range: false
            ,ready: formatminutes
        });

        laydate.render({
            elem: '#EndT'
            ,theme: '#133678'
            ,type: 'time'
            ,format: 'HH:mm'
            ,range: false
            ,ready: formatminutes
        });

        //切换模式
        form.on('select(Mode)', function(data){
            console.info(data.value);

            var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
            var nodeEn = czqPara.NodeEn[selectedTreeNode.idx];
            nodePara.Mode = data.value;
            console.info(nodePara,nodeEn);
            refreshNodePara(nodePara,nodeEn);
        });

        //监听提交
        form.on('submit(btn_search)', function(data){
            console.info(data.field);
            search(data.field);
            return false;
        });

        //批量升级终端
        form.on('submit(btn_update_device)', function(data){
            var checkStatus = table.checkStatus('table'); //idTest 即为基础参数 id 对应的值
            var checkItems = checkStatus.data;
            console.log(checkItems); //获取选中行的数据
            if(checkItems.length==0){
                toastr.warning("请先勾选终端");
            }
            else{
                var device_type=checkItems[0].device_type;
                var device_addr_arr = [];
                for(var i=0;i<checkItems.length;i++){
                    device_addr_arr.push(checkItems[i].device_addr)
                }
                var device_addrs = device_addr_arr.join(",");

                $("#form_update")[0].reset();

                layer.open({
                    //area: 'auto',
                    area:['400px','350px'],
                    type: 1,
                    shade: 0.5,
                    shadeClose: true,
                    title: '批量升级:'+checkItems.length+"个终端", //不显示标题
                    content: $('#form_update'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                    btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        lay_index=index;
                        var submit = layero.find("#btn_update");
                        submit.click();
                    }
                });

                $.ajax({
                    type: 'get',
                    url: '../Api/Firmware',
                    //data: {type:item.device_type},
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    dataType: "json",
                    success: function (res) {

                        firmwares =res.data;

                        //var default_filename = '';

                        var html="";
                        if(is_admin)
                        {
                            //可以升级所有终端
                            if(device_type=="HZFGW")
                            {
                                for(var i=0;i<firmwares.length;i++){
                                    if(firmwares[i].type=="HZFGW"){
                                        html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                                    }
                                }
                                for(var i=0;i<firmwares.length;i++){
                                    if(firmwares[i].type=="DMXFGW"|| firmwares[i].type=="DMXFGW"){
                                        html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                                    }
                                }
                            }
                            else if(device_type=="DMXFGW" || device_type=="DMXFGW")
                            {
                                for(var i=0;i<firmwares.length;i++){
                                    if(firmwares[i].type=="DMXFGW"|| firmwares[i].type=="DMXFGW"){
                                        html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                                    }
                                }
                                for(var i=0;i<firmwares.length;i++){
                                    if(firmwares[i].type=="HZFGW"){
                                        html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                                    }
                                }
                            }
                        }
                        else{
                            for(var i=0;i<firmwares.length;i++){
                                //只能升级对应类型终端
                                if(firmwares[i].type==device_type){
                                    html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+"</option>";
                                }
                            }
                        }
                        

                        $("select[name='id']").html(html);
                        form.render('select');

                        form.val("form_update", {batch:'1',addr:device_addrs,device_type:device_type});
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg('加载固件失败');
                    }
                });
            }
            return false;
        });

        //批量升级饲喂器
        form.on('submit(btn_update_feednode)', function(data){
            var checkStatus = table.checkStatus('table'); //idTest 即为基础参数 id 对应的值
            var checkItems = checkStatus.data;
            console.log(checkItems); //获取选中行的数据
            if(checkItems.length==0){
                toastr.warning("请先勾选终端");
            }
            else{
                var device_type=checkItems[0].device_type;
                var device_addr_arr = [];
                for(var i=0;i<checkItems.length;i++){
                    device_addr_arr.push(checkItems[i].device_addr)
                }
                var device_addrs = device_addr_arr.join(",");
                $("#form_update_node")[0].reset();
                $(".saddr").hide();
                layer.open({
                    //area: 'auto',
                    area:['400px','400px'],
                    type: 1,
                    shade: 0.5,
                    shadeClose: true,
                    title: '批量升级:'+checkItems.length+"个终端的饲喂器", //不显示标题
                    content: $('#form_update_node'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
                    btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        lay_index=index;
                        var submit = layero.find("#btn_update_node");
                        submit.click();
                    }
                });

                $.ajax({
                    type: 'get',
                    url: '../Api/Firmware',
                    //data: {type:device_type},
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    dataType: "json",
                    success: function (res) {

                        firmwares =res.data;

                        //var default_filename = '';
                        var html="";
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGWN_NODE"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                            }
                        }

                        $("select[name='id']").html(html);
                        form.render('select');

                        //form.val("form_update_node", {addr:item.device_addr,filename:default_filename,device_type:device_type});
                        //form.val("form_update_node", {addr:item.device_addr,device_type:device_type});
                        form.val("form_update_node", {batch:'1',addr:device_addrs,device_type:device_type});
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.msg('加载固件失败');
                    }
                });
            }
            return false;
        });

        form.on('submit(btn_ok)', function(data){
            console.info(data.field);
            //return
            layer.load(1);
            $.ajax({
                type: data.field.id.length>0?'PUT':'POST',
                url:"../Api/Device",
                data: data.field,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(data){
                    if(data){
                        if(data.code>=0){
                            toastr.success(res.msg);
                            layui.table.reload('table'); //重载表格
                            layer.close(lay_index); //再执行关闭
                        }else{
                            //layer.alert(data.msg);
                            toastr.warning(data.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        });
        form.on('submit(btn_update)', function(data){
            if(firmwares.length>0){
                var filename='';
                var type='';
                for(var i=0;i<firmwares.length;i++){
                    if(firmwares[i].id == data.field.id){
                        filename = firmwares[i].name;
                        type = firmwares[i].type;
                        break;
                    }
                }
                if(filename==""){
                    toastr.warning(res.msg, "固件异常");
                }else{
                    data.field.filename = filename;
                    data.field.type = type;
                    console.info("device_type",data.field.device_type);
                    console.info("type",type);

                    if(data.field.device_type!=type){
                        layer.confirm('选取的固件类型与当前的设备类型不一致,确认要升级?', function(index){
                            layer.close(index);
                            doUpdate(data.field);
                        });
                    }else{
                        doUpdate(data.field);
                    }
                }

                //doUpdate(data.field);
            }else{
                toastr.warning(res.msg, "固件加载失败");
            }
            
            
        });

        //批量同步网关名称 btn_sync_name
        form.on('submit(btn_sync_name)', function(data){
            var checkStatus = table.checkStatus('table'); //idTest 即为基础参数 id 对应的值
            var checkItems = checkStatus.data;
            console.log(checkItems); //获取选中行的数据

            if(checkItems.length==0){
                toastr.warning("请先勾选终端");
                return false;
            }

            layer.confirm('需要对勾选的'+checkItems.length+'个终端进行信息同步?', function(index){
                layer.close(index);
                doSyncName(checkItems);
            });
            return false;
        });

        form.on('submit(btn_sync_limit)', function(data){
            var checkStatus = table.checkStatus('table'); //idTest 即为基础参数 id 对应的值
            var checkItems = checkStatus.data;
            console.log(checkItems); //获取选中行的数据

            if(checkItems.length==0){
                toastr.warning("请先勾选终端");
                return false;
            }

            layer.confirm('需要对勾选的'+checkItems.length+'个终端进行信息同步?', function(index){
                layer.close(index);
                doSyncLimit(checkItems);
            });
            return false;
        });


        form.on('submit(btn_update_node)', function(data){
            
            if(firmwares.length>0){
                var filename='';
                var type='';
                for(var i=0;i<firmwares.length;i++){
                    if(firmwares[i].id == data.field.id){
                        filename = firmwares[i].name;
                        type = firmwares[i].type;
                        break;
                    }
                }
                if(filename==""){
                    toastr.warning(res.msg, "固件异常");
                }else{
                    data.field.filename = filename;
                    data.field.type = type;
                    //console.info(data.field);
                    console.info("device_type",data.field.device_type);
                    console.info("type",type);
                    if(data.field.device_type =="DMXFGW" && type=="HZFGWN_NODE"){
                        doUpdateNode(data.field);
                    }else if(data.field.device_type =="DMXFGW" && type=="HZFGW_NODE"){
                        doUpdateNode(data.field);
                    }else{
                        layer.confirm('选取的固件类型与当前的设备类型不一致,确认要升级?', function(index){
                            layer.close(index);
                            doUpdateNode(data.field);
                        });
                    }
                }

                //doUpdate(data.field);
            }else{
                toastr.warning(res.msg, "固件加载失败");
            }
        });
        //保存时间点
        form.on('submit(btn_time_edit_ok)', function(data){
            var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
            console.info(data.field);


            //备份之前数据
            var old_StartT = nodePara.StartT[data.field.Idx-1];
            var old_EndT = nodePara.EndT[data.field.Idx-1];
            var old_OutT = nodePara.OutT[data.field.Idx-1];

            nodePara.StartT[data.field.Idx-1] = data.field.StartT;
            nodePara.EndT[data.field.Idx-1] = data.field.EndT;
            nodePara.OutT[data.field.Idx-1] = data.field.OutT;
            //判断是否超过范围
            var sum=0;
            for(var i=0;i<6;i++){
                sum+=parseInt(nodePara.OutT[i]);
            }

            var err="";
            if(sum>100){
                err+="出料量之和不能超过100% ";
                nodePara.StartT[data.field.Idx-1] = old_StartT;
                nodePara.EndT[data.field.Idx-1] = old_EndT;
                nodePara.OutT[data.field.Idx-1] = old_OutT;
            }

            var start =parseInt(data.field.StartT.replace(':',''));
            var end = parseInt(data.field.EndT.replace(':',''));
            if(end<=start){
                err+="开始时间不能大于或等于结束时间 ";
                nodePara.StartT[data.field.Idx-1] = old_StartT;
                nodePara.EndT[data.field.Idx-1] = old_EndT;
                nodePara.OutT[data.field.Idx-1] = old_OutT;
            }

            if(err.length>0){
                toastr.warning(err, "提示");
            }else{
                layer.close(lay_index);
            }
            

            showTableTime(nodePara);
            

        });
        //保存曲线点
        form.on('submit(btn_curve_edit_ok)', function(data){
            var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
            console.info(data.field.id);
            // for(var i=0;i<curve_data.length;i++)
            // {
            //     if(curve_data[i].id == data.field.id)
            //     {
            //         curve_data[i].OutDay = data.field.OutDay;
            //         curve_data[i].OutMax = data.field.OutMax;
            //         break;
            //     }
            // }
            nodePara.OutDay[data.field.id] = data.field.OutDay;
            nodePara.OutDayType[data.field.id] = data.field.OutDayType;
            nodePara.OutMax[data.field.id] = data.field.OutMax;


            showTableCurve(nodePara);
            layer.close(lay_index);

        });

        form.on('submit(btn_save_param)', function(data){
            var addr = czqPara.Addr;
            console.info(addr);
            ApplyPara(data.field);
            console.info(czqPara);

            layer.load(1);
            $.ajax({
                type: 'PUT',
                url: '../Api/Device/HZFGW/Param',
                data: {addr:addr,params:JSON.stringify(czqPara)},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layer.close(lay_index);
                            toastr.success(res.msg);
                        }else{
                            //layer.alert(res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        });

        form.on('submit(btn_save_node_param)', function(data){
            saveNodePara(data.field);
        });


        form.on('submit(btn_allocate)', function(data){
            data.field.users = selectUser.getValue('valueStr');
            console.info(data.field);
            //return ;
            layer.load(1);
            $.ajax({
                type: 'PUT',
                url: '../Api/Device/Allocate',
                data: data.field,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layui.table.reload('table'); //重载表格
                            layer.close(lay_index); //再执行关闭
                        }else{
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        });

        //头工具栏事件
        table.on('toolbar(table)', function(obj){
            switch(obj.event){
                case 'addDevice':
                    onAdd();
                    break;

            };
        });

        //监听行工具事件
        table.on('tool(table)', function(obj){
            var data = obj.data;
            if(data.remark){

            }else{
                data.remark="";
            }
            console.log(obj)
            if(obj.event === 'delete'){
                onDelete(data);
            }
            else if(obj.event === 'edit'){
                onEdit(data);
            }
            else if(obj.event === 'update'){
                onUpdate(data);
            }
            else if(obj.event === 'updateNode'){
                onUpdateNode(data);
            }
            else if(obj.event === 'param'){
                //console.info(data)
                if(data.device_type=="HZFGW"){
                    onParam(data);
                }else if(data.device_type=="DMXFGW"){
                    onParamNew(data);
                }
            }
            else if(obj.event === 'status'){
                onStatus(data);
            }
            else if(obj.event === 'allocate'){
                onAllocate(data);
            }
        });

        table.on('tool(table_time)', function(obj){
            var item = obj.data;
            //console.log(item)
            if(obj.event === 'edit'){
                onEditTime(item);
            }else if(obj.event === 'reset'){
                onResetTime(item);
            }
        });

        table.on('tool(table_curve)', function(obj){
            var item = obj.data;
            //console.log(item)
            if(obj.event === 'edit'){
                onEditCurve(item);
            }else if(obj.event === 'reset'){
                onResetCurve(item);
            }
        });


        //加载tree
        loadTree();

        resize();


    });


    function getFont(treeId, node) {
        return node.font ? node.font : {};
    }


    function deepCopy(obj) {
        if (typeof obj != 'object') {
            return obj;
        }
        var newobj = {};
        for (var attr in obj) {
            newobj[attr] = deepCopy(obj[attr]);
        }
        return newobj;
    }

    function renderSelect(){
        //下拉
        var html="<option value='' ></option>";
        for(var i=0;i<device_define.length;i++){
            var selectd="";
            html+="<option "+selectd+" value=\""+device_define[i].device_type+"\">"+device_define[i].device_desc+"</option>";

        }

        $("select[name='device_type']").html(html);


        form.render('select');
    }

    function initTable(){
        //判断是否有分配权限
        /*var allocate = false;
        for(var i=0;i<actions.length;i++){
            if(actions[i].action_id=="allocate"){
                allocate = true;
                break;
            }
        }
        console.info(actions,allocate)*/

        var obj=form.val("form_search");
        console.info(obj);
        if(selectedTreeNode.type=="house"){
            obj.houseid = selectedTreeNode.id;
        }else if(selectedTreeNode.type=="farm"){
            obj.farmid = selectedTreeNode.id;
        }


        Table = table.render({
            elem: '#table'

            ,url: "../Api/Device/Page"
            ,height: 'full-70'
            ,method:'GET'
            ,headers : {'Authorization': 'Bearer '+window.localStorage.getItem("token")}
            ,where: obj
            ,page: true
            ,limit:100
            ,limits:[10,20,50,100,200]
            //,toolbar: '#table_toolbar' //开启头部工具栏，并为其绑定左侧模板
            ,defaultToolbar: ['']
            ,title: ''
            ,even:true
            ,size: 'sm' //小尺寸的表格
            // ,skin: 'nob' //无框风格
            ,cols: [[
                {type: 'checkbox',width:80, title:'全选'}
                /*{field:'device_type', title:'设备类型',width:130, sort: true,templet: function(d) {
                        var html = "";
                        for(var i=0;i<device_define.length;i++){
                            if(d.device_type == device_define[i].device_type){
                                html = device_define[i].device_desc;
                                break;
                            }
                        }
                        return html;
                    }}*/
                ,{field:'online', title:'在线状态',width:90, sort: false,align:'center',templet: function(d){
                        var html = "";
                        if(d.online){
                            html+="<span class=\"layui-badge-dot layui-bg-blue\"></span> 在线"
                        }else{
                            html+="<span class=\"layui-badge-dot layui-bg-black\"></span>  离线"
                        }
                        return html;
                    }}
                ,{field:'farmname', title:'养殖场', sort: true,minWidth:150, templet: function(d) {
                        if(d.farmname && d.farmname.length>0){
                            return d.farmname;
                        }else{
                            return "<span class='layui-text-red'>尚未设置</span>";
                        }

                    }}
                ,{field:'housename', title:'单元名称', sort: true,minWidth:120, templet: function(d) {
                        if(d.housename && d.housename.length>0){
                            return d.housename;
                        }else{
                            return "<span class='layui-text-red'>尚未设置</span>";
                        }
                    }}
                
                //,{field:'remark', title:'单元名称',minWidth:100, sort: true}
                
                ,{field:'device_addr', title:'网关SN',width:100, sort: true}

                ,{field:'version', title:'网关版本号',width:180, templet: function(d) {
                        var html="";
                        if(d.version){
                            if(d.device_type=="DMXFGW" && d.version){
                                return "<span class='layui-text-black' >"+d.version+"</span>"
                            }else{
                                return d.version;
                            }
                        }else{
                            return "";
                        }
                        
                    }, sort: false}
                ,{field:'node_num', title:'子设备数',minWidth:90, sort: false}
                ,{field:'node_version', title:'子设备版本',width:130, templet: function(d) {
                        var html="";
                        if(d.node_version){
                            var arr = d.node_version.split(",")
                            if(arr.length>1){
                                //多个版本
                                html = "<span class='layui-text-orange' >多种</span>";
                            }else if(arr.length==1){
                                html = "<span class='layui-text-black' >"+arr[0]+"</span>"
                            }else{
                                html = "无";
                            }
                        }else{
                            html = "无";
                        }
                        
                        return html;
                        
                    }, sort: false}
                ,{field:'node_num', title:'在线子设备',width:110, sort: false, templet: function(d) {
                        var html="";
                        if(parseInt(d.active_node_num)==parseInt(d.online_node_num) && parseInt(d.active_node_num)>0){
                            html = "<span class='layui-text-green-light' >"+d.online_node_num+"/"+d.active_node_num+"</span>";
                        }else{
                            html = "<span class='layui-text-orange' >"+d.online_node_num+"/"+d.active_node_num+"</span>";
                        }
                        return html;
                    }}
                ,{field:'node_num', title:'升级状态',width:150, sort: false, templet: function(d) {
                        var html="";
                        html = "<span class='' id='addr-"+d.device_addr+"' ></span>";
                        return html;
                    }}
                /*,{field:'alarm', title:'告警',width:80, sort: false,align:'center',templet: function(d){
                        return d.alarm>0?"<i class=\"layui-icon layui-icon-tips layui-text-red \"></i>":"";
                    }}*/

                // ,{field:'userids',hide:!allocate, title:'分配用户',width:130, sort: false,align:'center',templet: function(d){
                //         return d.userids?"<span class=\"layui-text-blue-light \" style='cursor: pointer;' onclick='onAllocate("+d.id+")' >已分配</span>":"";
                //     }}

                //,{fixed: 'right', title:'',width:150, toolbar:'#table_action_bar'}
                ,{field:'', title:'操作', width:250,sort: false,align:'left', fixed: 'right', templet: function(d) {
                        var html = "";
                        if(d.housename && d.housename.length>0){
                            //html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit\" lay-event=\"edit\">修改</a>";
                            //html += "<a href='#'   class=\"layui-hide action-edit\" lay-event=\"edit\"><span class=\" layui-text-orange \">修改</span></a><span class=\"shortGreyLine\"></span>";
                        }else{

                        }


                        if (d.device_type=="HZFGW"){
                            //html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-view \" lay-event=\"status\">设备状态</a>";
                            html += "<a href='#'   class=\"layui-hide action-view\" lay-event=\"status\"><span class=\"  layui-text-grey text-underline\">状态</span></a><span class=\"shortGreyLine\"></span>";
                            //html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-view btn-param\" lay-event=\"param\">参数</a>";
                            html += "<a href='#'   class=\"layui-hide action-view\" lay-event=\"param\"><span class=\" layui-text-grey text-underline \">参数</span></a><span class=\"shortGreyLine\"></span>";
                            // html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit btn-read-clock\" lay-event=\"getClock\">设备时间</a>";
                            // html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit btn-set-clock\" lay-event=\"setClock\">校时</a>";
                            // html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-update\" lay-event=\"update\">升级终端</a>";
                            // html += "<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-update\" lay-event=\"updateNode\">升级饲喂器</a>";
                            html += "<a href='#'   class=\"layui-hide action-update\" lay-event=\"update\"><span class=\" layui-text-grey text-underline \">升级终端</span></a><span class=\"shortGreyLine\"></span>";
                            html += "<a href='#'   class=\"layui-hide action-update\" lay-event=\"updateNode\"><span class=\" layui-text-grey text-underline \">升级饲喂器</span></a><span class=\"shortGreyLine layui-hide\"></span>";
                        }
                        else if(d.device_type=="DMXFGW"){
                            html += "<a href='#'   class=\"layui-hide action-view\" lay-event=\"status\"><span class=\"  layui-text-grey text-underline\">状态</span></a><span class=\"shortGreyLine layui-hide action-view\"></span>";
                            html += "<a href='#'   class=\"layui-hide action-view\" lay-event=\"param\"><span class=\" layui-text-grey text-underline \">参数</span></a><span class=\"shortGreyLine layui-hide action-view\"></span>";
                            html += "<a href='#'   class=\"layui-hide action-update\" lay-event=\"update\"><span class=\" layui-text-grey text-underline \">升级终端</span></a><span class=\"shortGreyLine layui-hide action-update\"></span>";
                            html += "<a href='#'   class=\"layui-hide action-update\" lay-event=\"updateNode\"><span class=\" layui-text-grey text-underline \">升级饲喂器</span></a><span class=\"shortGreyLine layui-hide\"></span>";
                        }

                        //html += "<a class=\" layui-btn layui-btn-normal layui-btn-xs layui-hide action-delete\" lay-event=\"delete\">删除</a>";
                        return html;
                    }}
            ]]
            ,done: function(res, curr, count){
                for(var i=0;i<actions.length;i++){
                    $('.action-'+actions[i].action_id).removeClass("layui-hide");
                }
                var that = this.elem.next();
                allData = res.data;
                res.data.forEach(function (item, index) {
                    //console.log(item.empName);item表示每列显示的数据
                    setTimeout(function(){
                        $(".layui-table-main tr").each(function (index, val) {
                            var h = $(val).height();
                            console.info(h);
                            $(".layui-table-fixed").each(function () {
                                $($(this).find(".layui-table-body tbody tr")[index]).height(h);
                            });
                            $(val).height(h);
                        });
                        $(".layui-table-header tr").each(function (index, val) {
                            var h = $(val).height();
                            //console.info(h);
                            $(".layui-table-fixed").each(function () {
                                $($(this).find(".layui-table-header thead tr")[index]).height(h);
                            });
                            $(val).height(h);
                        });
                    },500);

                    if(allData.length==1){
                        setTimeout(function(){
                            console.info(item);

                            getParam(item).then(function(res){
                                if(res.code>=0){
                                    console.info(res.msg);

                                    setTimeout(function(){
                                        getStatus(item).then(function(res){
                                            if(res.code>=0){
                                            }
                                        });
                                    },2000);
                                    
                                }
                            });
                        },1000)
                    }
                    
                    

                    getUpdateStatus(item.device_addr).then(function(res){
                        if(res.code>=0){
                            /*
                            Ug_State uint8  //0:没有升级 1:发送文件信息 2:发送文件内容
                            Ug_one   uint8  //0:全部升级 1:单个升级
                            Ug_tn    uint8  //正在升级节点的tn号,从0开始
                            Ug_try   uint8  //重试次数
                            Ug_pkg   uint16 //第几个数据包
                            Ug_Tpkg  uint16 //总共几个数据包
                            Ug_sn    uint32 //正在升级节点的SN
                            */
                           
                            var str = "";
                            if(res.data){
                                if(res.data.Ug_State==1){
                                    str += "发文件信息"
                                    str+="<br>";
                                    str+=("饲喂器序号:"+res.data.Ug_tn);
                                    $("#addr-"+item.device_addr).html(str);
                                }
                                else if(res.data.Ug_State==2){
                                    str+="发送文件内容"
                                    // if(res.data.Ug_one){
                                    //     str = "单个"+str;
                                    // }else{
                                    //     str = "全部"+str;
                                    // }
                                    str+="<br>";

                                    //传输数据包
                                    str+=(" 数据包:"+res.data.Ug_pkg+"/"+res.data.Ug_Tpkg);
                                    str+="<br>";
                                    //正在升级节点的tn号
                                    str+=(" 饲喂器序号:"+res.data.Ug_tn);

                                    $("#addr-"+item.device_addr).html(str);
                                }
                                else{
                                    $("#addr-"+item.device_addr).html("未在升级");
                                }
                                
                            }else{
                                $("#addr-"+item.device_addr).html("N/A");
                            }
                        }
                        else{
                            $("#addr-"+item.device_addr).html("Err");
                        }
                    });

                    

                    if (!item.online) {
                        //var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "#ccc");
                    } else {
                        //var tr = that.find(".layui-table-box tbody tr[data-index='" + index + "']").css("background-color", "#fff");
                    }

                    setTimeout(function(){ window.dispatchEvent(new Event('resize'))},200);
                });

                
            }
        });
    }

    function onAdd() {
        $("#form")[0].reset();
        layer.open({
            //area: 'auto',
            area:['450px','400px'],
            offset: '10%',
            shade: 0.5,
            shadeClose: true,
            type: 1,
            title: '新增', //不显示标题
            content: $('#form'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            maxmin: false,
            btn: ['确定', '取消'],
            yes: function(index, layero){
                //点击确认触发 iframe 内容中的按钮提交
                lay_index=index;
                var submit = layero.contents().find("#btn_ok");
                submit.click();
            }
        });
    }

    function onEdit(item) {
        console.info(item);
        form.val('form',item);

        layer.open({
            //area: 'auto',
            area:['450px','400px'],
            offset: '10%',
            shade: 0.5,
            shadeClose: true,
            type: 1,
            title: '修改', //不显示标题
            content: $('#form'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            maxmin: false,
            btn: ['确定', '取消'],
            yes: function(index, layero){
                //点击确认触发 iframe 内容中的按钮提交
                lay_index=index;
                var submit = layero.contents().find("#btn_ok");
                submit.click();
            }
        });


    }
    


    function onEditTime(item) {
        $("#form_time")[0].reset();
        form.val("form_time", item);
        layer.open({
            //area: 'auto',
            area:['400px','300px'],
            type: 1,
            shade: 0.3,
            title: '序号'+item.Idx, //不显示标题
            content: $('#form_time'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['确定', '取消']
            ,yes: function(index, layero){
                lay_index=index;
                var submit = layero.find("#btn_time_edit_ok");
                submit.click();
            }
        });
    }

    function onResetTime(item) {

        console.info(item);
        var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
        console.info(item.Idx-1);
        nodePara.StartT[item.Idx-1] = "00:00";
        nodePara.EndT[item.Idx-1] = "00:00";
        nodePara.OutT[item.Idx-1] = 0;

        /*for(var i=0;i<time_data.length;i++)
        {
            if(time_data[i].Idx == item.Idx)
            {
                nodePara.StartT[i] = "00:00";
                nodePara.EndT[i] = "00:00";
                nodePara.OutT[i] = 0;
                break;
            }
        }*/


        showTableTime(nodePara);
    }

    function onEditCurve(item) {
        console.info(item);
        $("#form_curve")[0].reset();
        form.val("form_curve", item);
        layer.open({
            //area: 'auto',
            area:['400px','300px'],
            type: 1,
            shade: 0.3,
            title: '序号'+item.No, //不显示标题
            content: $('#form_curve'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['确定', '取消']
            ,yes: function(index, layero){
                lay_index=index;
                var submit = layero.find("#btn_curve_edit_ok");
                submit.click();
            }
        });
    }

    function onResetCurve(item) {
        console.info(item);

        var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
        console.info(item.id);
        nodePara.OutDay[item.id] = 0;
        nodePara.OutDayType[item.id] = 0;
        nodePara.OutMax[item.id] = 0;


        showTableCurve(nodePara);
    }

    function onDelete(item) {
        layer.confirm('确认删除'+item.remark+"?", function(index){
            //obj.del();
            layer.load(1);
            $.ajax({
                type: 'DELETE',
                url:"../Api/Device",
                data: item,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                dataType: "json",
                success: function (res) {
                    //console.info(data)
                    if(res.code==0){
                        //layer.msg('成功');
                        toastr.success('删除成功');
                        layui.table.reload('table'); //重载表格
                        layer.close(index); //再执行关闭
                    }else{
                        toastr.warning(res.msg, "异常");
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('失败');
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
            });
        });
    }

    var firmwares=[];
    function onUpdate(item) {
        $("#form_update")[0].reset();

        layer.open({
            //area: 'auto',
            area:['400px','350px'],
            type: 1,
            shade: 0.5,
            shadeClose: true,
            title: '升级:'+item.remark, //不显示标题
            content: $('#form_update'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['确定', '取消']
            ,yes: function(index, layero){
                lay_index=index;
                var submit = layero.find("#btn_update");
                submit.click();
            }
        });

        $.ajax({
            type: 'get',
            url: '../Api/Firmware',
            //data: {type:item.device_type},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {

                firmwares =res.data;

                //var default_filename = '';

                var html="";
                if(is_admin)
                {
                    //可以升级所有终端
                    if(item.device_type=="HZFGW")
                    {
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGW"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                            }
                        }
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="DMXFGW"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                            }
                        }
                    }
                    else if(item.device_type=="DMXFGW")
                    {
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="DMXFGW"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                            }
                        }
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGW"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                            }
                        }
                    }
                }
                else{
                    for(var i=0;i<firmwares.length;i++){
                        //只能升级对应类型终端
                        if(firmwares[i].type==item.device_type){
                            html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+"</option>";
                        }
                    }
                }
                

                $("select[name='id']").html(html);
                form.render('select');

                form.val("form_update", {batch:"0",addr:item.device_addr,device_type:item.device_type});
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载固件失败');
            }
        });
    }

    function onUpdateNode(item) {
        $("#form_update_node")[0].reset();
        $(".saddr").show();
        layer.open({
            //area: 'auto',
            area:['400px','400px'],
            type: 1,
            shade: 0.5,
            shadeClose: true,
            title: '升级:'+item.remark, //不显示标题
            content: $('#form_update_node'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['确定', '取消']
            ,yes: function(index, layero){
                lay_index=index;
                var submit = layero.find("#btn_update_node");
                submit.click();
            }
        });

        $.ajax({
            type: 'get',
            url: '../Api/Firmware',
            //data: {type:item.device_type},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {

                firmwares =res.data;

                //var default_filename = '';
                var html="";
                if(is_admin)
                {
                    //可以升级所有终端
                    if(item.device_type=="HZFGW")
                    {
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGW_NODE"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                            }
                        }
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGWN_NODE"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                            }
                        }
                    }
                    else if(item.device_type=="DMXFGW")
                    {
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGWN_NODE"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (新版)</option>";
                            }
                        }
                        for(var i=0;i<firmwares.length;i++){
                            if(firmwares[i].type=="HZFGW_NODE"){
                                html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+" (旧版)</option>";
                            }
                        }
                    }
                }
                else{
                    for(var i=0;i<firmwares.length;i++){
                        //只能升级对应类型终端
                        if(firmwares[i].type==(item.device_type+"_NODE")){
                            html+="<option "+" value=\""+firmwares[i].id+"\">"+firmwares[i].name+"</option>";
                        }
                    }
                }

                $("select[name='id']").html(html);
                form.render('select');

                //form.val("form_update_node", {addr:item.device_addr,filename:default_filename,device_type:item.device_type});
                form.val("form_update_node", {batch:"0",addr:item.device_addr,device_type:item.device_type});
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载固件失败');
            }
        });
    }

    function doUpdate(data){
        console.info(data);
        if(data.batch=="1"){
            //批量
            var device_addr_arr = data.addr.split(",");
            layer.load(1);
            for(var i=0;i<device_addr_arr.length;i++){
                data.addr = device_addr_arr[i];
                var url = '../Api/Device/Gw/Update';
                $.ajax({
                    type: 'PUT',
                    url: url,
                    data: data,
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    success: function(res){
                        if(res){
                            if(res.code>=0){
                                //保存成功
                                layer.close(lay_index);
                                toastr.success(res.msg);
                            }else{
                                //layer.alert(res.msg);
                                toastr.warning(res.msg, "异常");
                            }
                        }
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                    dataType: "json"
                });
            }
        }else{
            //单个
            var url = '../Api/Device/Gw/Update';
            console.info(url);
            //return ;
            layer.load(1);
            $.ajax({
                type: 'PUT',
                url: url,
                data: data,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layer.close(lay_index);
                            toastr.success(res.msg);
                        }else{
                            //layer.alert(res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        }

        
    }

    function doSyncName(checkItems){
        for(var i=0;i<checkItems.length;i++){
            var addr = checkItems[i].device_addr;
            var SiteName = checkItems[i].farmname;
            var HouseName = checkItems[i].housename;
            var url =  '../Api/Device/Gw/ExParamName';
            $.ajax({
                type: 'PUT',
                url: url,
                data: {addr:addr,SiteName:SiteName,HouseName:HouseName},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layer.close(lay_index);
                            toastr.success(res.msg);
                        }else{
                            //layer.alert(res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        }
    }

    function doSyncLimit(checkItems){
        for(var i=0;i<checkItems.length;i++){
            var addr = checkItems[i].device_addr;
            var MaxNode = checkItems[i].node_num;
            var EnMaxNode = "1";
            var url =  '../Api/Device/Gw/ExParamLimit';
            $.ajax({
                type: 'PUT',
                url: url,
                data: {addr:addr,EnMaxNode:EnMaxNode,MaxNode:MaxNode},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layer.close(lay_index);
                            toastr.success(res.msg);
                        }else{
                            //layer.alert(res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        }
    }

    function doUpdateNode(data){
        console.info(data);
        if(data.batch=="1"){
            //批量
            var device_addr_arr = data.addr.split(",");
            layer.load(1);
            for(var i=0;i<device_addr_arr.length;i++){
                data.addr = device_addr_arr[i];
                var url = '../Api/Device/Gw/UpdateNode';
                $.ajax({
                    type: 'PUT',
                    url: url,
                    data: data,
                    beforeSend: function(request) {
                        request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                    },
                    success: function(res){
                        if(res){
                            if(res.code>=0){
                                //保存成功
                                layer.close(lay_index);
                                toastr.success(res.msg);
                            }else{
                                //layer.alert(res.msg);
                                toastr.warning(res.msg, "异常");
                            }
                        }
                    },
                    complete: function(XMLHttpRequest, textStatus) {
                        layer.closeAll('loading');
                    },
                    dataType: "json"
                });
            }
        }else{
            //单个
            var url = '../Api/Device/Gw/UpdateNode';
            $.ajax({
                type: 'PUT',
                url: url,
                data: data,
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function(res){
                    if(res){
                        if(res.code>=0){
                            //保存成功
                            layer.close(lay_index);
                            toastr.success(res.msg);
                        }else{
                            //layer.alert(res.msg);
                            toastr.warning(res.msg, "异常");
                        }
                    }
                },
                complete: function(XMLHttpRequest, textStatus) {
                    layer.closeAll('loading');
                },
                dataType: "json"
            });
        }
        
    }

    //获取升级状态
    function getUpdateStatus(addr){
        var promise = new Promise(function(resolve, reject) {
            $.ajax({
                type: 'GET',
                url: '../Api/Device/Gw/UpdateStatus',
                data: {addr:addr},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function (data) {

                    if (data && data.code>=0) {
                        resolve(data);
                    }else{
                        resolve(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    reject(err);
                },
                complete: function(XMLHttpRequest, textStatus) {

                },
                dataType: "json"
            });
        });
        return promise;
    }

    //读取状态
    function getStatus(item){
        console.info(item);
        var url="";
        if(item.device_type=="HZFGW"){
            url = '../Api/Device/HZFGW/Status';
        }else if(item.device_type=="DMXFGW"){
            url = '../Api/Device/Gw/Status';
        }
        var promise = new Promise(function(resolve, reject) {
            $.ajax({
                type: 'GET',
                url: url,
                data: {addr:item.device_addr},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function (data) {

                    if (data && data.code>=0) {
                        resolve(data);
                    }else{
                        resolve(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    reject(err);
                },
                complete: function(XMLHttpRequest, textStatus) {

                },
                dataType: "json"
            });
        });
        return promise;
    }

    //读取参数
    function getParam(item){
        console.info(item);
        var url="";
        if(item.device_type=="HZFGW"){
            url = '../Api/Device/HZFGW/Param';
        }else if(item.device_type=="DMXFGW"){
            url = '../Api/Device/Gw/Param';
        }
        var promise = new Promise(function(resolve, reject) {
            $.ajax({
                type: 'GET',
                url: url,
                data: {addr:item.device_addr},
                beforeSend: function(request) {
                    request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
                },
                success: function (data) {

                    if (data && data.code>=0) {
                        resolve(data);
                    }else{
                        resolve(data);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    reject(err);
                },
                complete: function(XMLHttpRequest, textStatus) {

                },
                dataType: "json"
            });
        });
        return promise;
    }

    function onParam(item){
        select_device = item;
        layer.open({
            //area: 'auto',
            area:['80%','80%'],
            type: 1,
            shade: 0.5,
            shadeClose: true,
            title: '参数', //不显示标题
            content: $('#wd_param'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['保存','刷新','拷贝曲线&时间表','应用拷贝','清空参数','关闭']
            ,yes: function(index, layero){
                lay_index=index;
                if(selectedTreeNode){
                    if(selectedTreeNode.type=="HZFGW"){
                        var submit = layero.find("#btn_save_param");
                        submit.click();
                    }else{
                        var submit = layero.find("#btn_save_node_param");
                        submit.click();
                    }
                }else{
                    var submit = layero.find("#btn_save_param");
                    submit.click();
                }

                //layer.close(index);
            },btn2: function(index, layero){
                //按钮【按钮二】的回调
                loadPara(item);
                return false; //开启该代码可禁止点击该按钮关闭
            },btn3: function(index, layero){
                //拷贝曲线&时间表
                console.info(selectedTreeNode);
                if(selectedTreeNode && selectedTreeNode.type){
                    if(selectedTreeNode.type!="feed"){
                        layer.alert("请选择饲喂器");
                    }else{
                        var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
                        
                        copy_OutDay = [];
                        copy_OutMax = [];
                        for(var i=0;i<nodePara.OutDay.length;i++)
                        {
                            copy_OutDay.push(nodePara.OutDay[i]);
                            copy_OutMax.push(nodePara.OutMax[i]);
                        }
                        copy_StartT = [];
                        copy_EndT = [];
                        copy_OutT = [];
                        for(var i=0;i<nodePara.StartT.length;i++)
                        {
                            copy_StartT.push(nodePara.StartT[i]);
                            copy_EndT.push(nodePara.EndT[i]);
                            copy_OutT.push(nodePara.OutT[i]);
                        }
                        has_copy=true;
                        layer.msg("拷贝成功");
                        console.info(copy_OutDay);
                        console.info(copy_OutMax);
                        console.info(copy_StartT);
                        console.info(copy_EndT);
                        console.info(copy_OutT);
                    }
                }else{
                    layer.alert("请选择饲喂器");
                }

                return false; //开启该代码可禁止点击该按钮关闭
            },btn4: function(index, layero){
                //应用拷贝
                if(selectedTreeNode && selectedTreeNode.type){
                    if(selectedTreeNode.type!="feed"){
                        layer.alert("请选择饲喂器");
                    }else{

                        var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
                        var nodeEn = czqPara.NodeEn[selectedTreeNode.idx];
                        
                        if(has_copy)
                        {
                            for(var i=0;i<nodePara.OutDay.length;i++)
                            {
                                nodePara.OutDay[i] = copy_OutDay[i];
                                nodePara.OutMax[i] = copy_OutMax[i];
                            }
                            for(var i=0;i<nodePara.StartT.length;i++)
                            {
                                nodePara.StartT[i] = copy_StartT[i];
                                nodePara.EndT[i] = copy_EndT[i];
                                nodePara.OutT[i] = copy_OutT[i];
                            }
                            refreshNodePara(nodePara,nodeEn);
                            //layer.msg("应用成功，请保存参数到饲喂器");
                        }
                        else
                        {
                            layer.alert("尚未拷贝任何参数");
                        }
                        
                    }
                }else{
                    layer.alert("请选择饲喂器");
                }
                return false; //开启该代码可禁止点击该按钮关闭
            },btn5:function(index,layero){
                if(selectedTreeNode && selectedTreeNode.type){
                    if(selectedTreeNode.type!="feed"){
                        layer.alert("请选择饲喂器");
                    }else{
                        resetNodePara();
                    }
                }else{
                    layer.alert("请选择饲喂器");
                }
                
                return false; //开启该代码可禁止点击该按钮关闭
            }
            ,cancel: function(index, layero){
                //右上角关闭回调
                layer.close(index);
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });

        $(".para").show();
        $(".node_para").hide();

        
        loadPara(item);
    }

    function onParamNew(item) {
        //loadParaNew(item);
        var idx = layer.open({
            area:['95%','85%'],
            type: 2,
            shadeClose: true,
            shade: 0.8,
            title: item.farmname+" "+item.housename+" "+item.device_addr,
            maxmin: false, //开启最大化最小化按钮
            content: '../Device/Para?'+$.param(item)
        });
        //layer.full(idx); //执行最大化
    }

    function onStatus(item) {
        console.info(item);
        device_type = item.device_type;
        layer.open({
            //area: 'auto',
            area:['80%','80%'],
            type: 1,
            shade: 0.5,
            shadeClose: true,
            title: item.remark + ' '+item.device_addr, //不显示标题
            content: $('#form_status'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            btn: ['确定','刷新','关闭']
            ,yes: function(index, layero){
                layer.close(index);
            },btn2: function(index, layero){
                //按钮【按钮二】的回调
                loadStatus(item);
                return false; //开启该代码可禁止点击该按钮关闭
            },cancel: function(index, layero){
                //右上角关闭回调
                layer.close(index);
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });

        $(".status").show();
        $(".node_status").hide();
        loadStatus(item);
    }

    function loadPara(item) {
        zTree = $.fn.zTree.init($("#tree1"), tree_setting, []);
        $("#form_param")[0].reset();
        layer.load(1);
        $.ajax({
            type: 'get',
            url: '../Api/Device/HZFGW/Param',
            data: {addr:item.device_addr},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    czqPara = res.data;
                    console.info(czqPara);


                    var rootNode={name:item.device_addr+" "+item.remark,type:item.device_type,children:[]};

                    for(var i=0;i<czqPara.NodeEn.length;i++){
                        rootNode.children.push({
                            idx:i,
                            type:'feed',
                            //name:czqPara.NodeParas[i].Sn,
                            name:(i+1).toString()+":["+(czqPara.NodeParas[i].Hnum).toString()+"] "+ czqPara.NodeParas[i].Sn,
                            enable:czqPara.NodeEn[i],
                            online:-1,
                        });
                    }

                    var nodes=[];
                    nodes.push(rootNode);

                    nodes=setDataIcon(nodes);
                    zTree = $.fn.zTree.init($("#tree1"), tree_setting, nodes);

                    if(czqPara.Dhcp==0){
                        czqPara.Dhcp = '';
                    }else{
                        czqPara.Dhcp = 'on';
                    }
                    form.val("form_param",czqPara);

                    resize();

                    if(select_node_idx!=null){
                        var nodes = zTree.getNodesByParam("idx", select_node_idx, null);
                        //console.info(nodes);
                        if(nodes.length>0){
                            const node = nodes[0];
                            console.info(node);
                            zTree.selectNode(node);
                            zTree.setting.callback.onClick(null,null,node);//手动触发onClick事件
                        }
                    }

                }else{

                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('读取设备状态失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });





    }

    function loadParaNew(item) {
        layer.load(1);
        $.ajax({
            type: 'get',
            url: '../Api/Device/Gw/Param',
            data: {addr:item.device_addr},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    czqPara = res.data;
                    console.info(czqPara);
                }else{
                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('读取设备参数失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },
        });
    }

    function loadStatus(item){
        $("#form_status")[0].reset();
        zTree = $.fn.zTree.init($("#tree2"), tree_setting1, []);

        var url="";
        if(item.device_type=="HZFGW"){
            url = '../Api/Device/HZFGW/Status';
        }else if(item.device_type=="DMXFGW"){
            url = '../Api/Device/Gw/Status';
        }

        layer.load(1);
        $.ajax({
            type: 'get',
            url: url,
            data: {addr:item.device_addr},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (res) {
                if(res.code>=0){
                    czqState = res.data;
                    console.info(czqState);


                    var rootNode={name:item.device_addr+" "+item.remark,type:item.device_type,children:[]};

                    for(var i=0;i<czqState.NodeSN.length;i++){
                        if(czqState.NodeMode[i]=="241"){
                            //拉料设备
                            rootNode.children.push({
                                idx:i,
                                type:'deliver',
                                name:(i+1).toString()+":[联动拉料] "+ (czqState.Enable[i]>0?czqState.NodeSN[i]:'') +" "+(czqState.Enable[i]>0?("版本:"+czqState.NodeStates[i].Version):''),
                                enable:czqState.Enable[i],
                                online:czqState.Online[i],
                                alarm:czqState.NodeStates[i].AlarmState,
                                sn:czqState.NodeSN[i],
                            });
                        }
                        else if(czqState.NodeMode[i]=="243"){
                            //补奶器
                            rootNode.children.push({
                                idx:i,
                                type:'bn',
                                name:(i+1).toString()+":[补奶器] "+ (czqState.Enable[i]>0?czqState.NodeSN[i]:'') +" "+(czqState.Enable[i]>0?("版本:"+czqState.NodeBnStates[i].Version):''),
                                enable:czqState.Enable[i],
                                online:czqState.Online[i],
                                alarm:czqState.NodeBnStates[i].AlarmState,
                                sn:czqState.NodeSN[i],
                            });
                        }
                        else if(czqState.NodeMode[i]=="245"){
                            //加药器
                            rootNode.children.push({
                                idx:i,
                                type:'jy',
                                name:(i+1).toString()+":[加药器] "+ (czqState.Enable[i]>0?czqState.NodeSN[i]:'') +" "+(czqState.Enable[i]>0?("版本:"+czqState.NodeJyStates[i].Version):''),
                                enable:czqState.Enable[i],
                                online:czqState.Online[i],
                                alarm:czqState.NodeBnStates[i].AlarmState,
                                sn:czqState.NodeSN[i],
                            });
                        }
                        else if(czqState.NodeMode[i]=="168"){
                            //粥料器
                            var hnum = czqState.Hnum[i].toString();
                            rootNode.children.push({
                                idx:i,
                                type:'fg',
                                name:(i+1).toString()+":[粥料器]"+"["+hnum+"] "+ (czqState.Enable[i]>0?czqState.NodeSN[i]:'') +" "+(czqState.Enable[i]>0?("版本:"+czqState.NodeFgStates[i].Version):''),
                                enable:czqState.Enable[i],
                                online:czqState.Online[i],
                                alarm:czqState.NodeFgStates[i].AlarmState,
                                sn:czqState.NodeSN[i],
                            });
                        }
                        else{
                            var hnum = czqState.Hnum[i].toString();
                            rootNode.children.push({
                                idx:i,
                                type:'feed',
                                name:(i+1).toString()+":["+hnum+"] "+ (czqState.Enable[i]>0?czqState.NodeSN[i]:'') +" "+(czqState.Enable[i]>0?("版本:"+czqState.NodeStates[i].Version):''),
                                enable:czqState.Enable[i],
                                online:czqState.Online[i],
                                alarm:czqState.NodeStates[i].AlarmState,
                            });
                        }
                        
                    }

                    var nodes=[];
                    nodes.push(rootNode);

                    nodes=setDataIcon(nodes);
                    zTree = $.fn.zTree.init($("#tree2"), tree_setting1, nodes);

                    if(czqState.ComType==0){
                        czqState.ComType = '以太网';
                    }else if(czqState.ComType==1){
                        czqState.ComType = '移动';
                    }else if(czqState.ComType==2){
                        czqState.ComType = '联通';
                    }else if(czqState.ComType==3){
                        czqState.ComType = '电信';
                    }
                    $("#title_version").html("版本号:"+czqState.Version);
                    form.val("form_status",czqState);
                    resize();

                }else{
                    $("#title_version").html("设备离线");

                    layer.alert(res.msg);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('读取设备状态失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },

        });
    }

    function refreshNodePara(nodePara,nodeEn) {
        var mode = parseInt(nodePara.Mode);
        nodePara["_EnWater"] = nodePara.EnWater>0?"on":"";
        nodePara["_enable"] = nodeEn>0?"on":"";
        if(mode>EMODE_IDLE) {
            //非停用
            nodePara["_TbTotalTime"] = nodePara.TbTotalTime[mode - 1];
            nodePara["_FeedWater"] = nodePara.FeedWater[mode - 1];
            nodePara["_YlCheck"] = nodePara.YlCheck[mode - 1] > 0 ? "on" : "";
            nodePara["_AutoOut"] = nodePara.AutoOut[mode - 1];
        }else{
            //停用
            nodePara["_TbTotalTime"]=0;
            nodePara["_FeedWater"]=0;
            nodePara["_YlCheck"]=0;
            nodePara["_AutoOut"]=0;
        }

        

        //公猪模式，不显示带仔相关,非公猪模式不显示 公猪年龄，公猪年龄附加
        if(mode==EMODE_BOAR){
            $(".div_Son").hide();
            $(".div_SonBase").hide();
            $(".div_AddSon").hide();
            $(".div_SonAge").hide();

            $(".div_AddAge").show();
            $(".div_Age").show();

        }else{
            $(".div_Son").show();
            $(".div_SonBase").show();
            $(".div_AddSon").show();
            $(".div_SonAge").show();

            $(".div_AddAge").hide();
            $(".div_Age").hide();
        }

            //体况附加
        $(".AddFit").show();
        if(mode==EMODE_PG){
            //妊娠
            nodePara["_AddFit"]=nodePara.AddFit[0];
        }else if(mode==EMODE_NP){
            //空怀
            nodePara["_AddFit"]=nodePara.AddFit[1];
        }else if(mode==EMODE_NURSE){
            //哺乳
            nodePara["_AddFit"]=nodePara.AddFit[2];
        }else if(mode==EMODE_BOAR){
            //公猪
            nodePara["_AddFit"]=nodePara.AddFit[3];
        }else{
            nodePara["_AddFit"]=0;
            $(".AddFit").hide();
        }

        //胎龄附加
        $(".AddSonAge").show();
        if(mode==EMODE_PG){
            //妊娠
            nodePara["_AddSonAge"]=nodePara.AddSonAge[0];
        }else if(mode==EMODE_NP){
            //空怀
            nodePara["_AddSonAge"]=nodePara.AddSonAge[1];
        }else if(mode==EMODE_NURSE){
            //哺乳
            nodePara["_AddSonAge"]=nodePara.AddSonAge[2];
        }else{
            nodePara["_AddSonAge"]=0;
            $(".AddSonAge").hide();
        }

        //引食量+喂料时间间隔
        $(".FFeed").show();
        $(".FeedTimeGap").show();
        if(mode==EMODE_CC){
            //保育
            nodePara["_FFeed"]=nodePara.FFeed[0];
            nodePara["_FeedTimeGap"]=nodePara.FeedTimeGap[0];
        }else if(mode==EMODE_FAT){
            //育肥
            nodePara["_FFeed"]=nodePara.FFeed[1];
            nodePara["_FeedTimeGap"]=nodePara.FeedTimeGap[1];
        }else if(mode==EMODE_NURSE){
            //哺乳
            nodePara["_FFeed"]=nodePara.FFeed[2];
            nodePara["_FeedTimeGap"]=nodePara.FeedTimeGap[2];
        }else{
            nodePara["_FFeed"]=0;
            nodePara["_FeedTimeGap"]=0;
            $(".FFeed").hide();
            $(".FeedTimeGap").hide();
        }

        console.info(nodePara);
        form.val("form_node_param",nodePara);
        showTableTime(nodePara);
        showTableCurve(nodePara);
    }

    function refreshNodeStatus(nodeState) {
        if(device_type){
            if(device_type=="HZFGW"){
                nodeState.Mode=decodeMode(nodeState.Mode);
                $(".lb_feed_water").html("料水比");
                if(nodeState.FeedWater==0){
                    nodeState.FeedWater="不出水";
                }else if(nodeState.FeedWater==1){
                    nodeState.FeedWater="1:1";
                }else if(nodeState.FeedWater==2){
                    nodeState.FeedWater="1:2";
                }else if(nodeState.FeedWater==3){
                    nodeState.FeedWater="1:3";
                }else if(nodeState.FeedWater==4){
                    nodeState.FeedWater="1:4";
                }else if(nodeState.FeedWater==4){
                    nodeState.FeedWater="1:5";
                }
            }else if(device_type=="DMXFGW"){
                nodeState.Mode=decodeModeNew(nodeState.Mode);
                $(".lb_feed_water").html("水料比");
            }else{

            }
        }


        

        if(nodeState.ManFeed>0){
            nodeState.ManFeed="运行";
        }else{
            nodeState.ManFeed="停止";
        }

        if(nodeState.ManWater>0){
            nodeState.ManWater="运行";
        }else{
            nodeState.ManWater="停止";
        }

        if(nodeState.TbAct>0){
            nodeState.TbAct="触发";
        }else{
            nodeState.TbAct="未触发";
        }

        if(nodeState.TAutoRun==0){
            nodeState.TAutoRun="无效";
        }else if(nodeState.TAutoRun==1){
            nodeState.TAutoRun="时段";
        }else{
            nodeState.TAutoRun="触碰杆";
        }

        if(nodeState.StepOut==0){
            nodeState.StepOut="预出水";
        }else if(nodeState.StepOut==1){
            nodeState.StepOut="出料出水";
        }else if(nodeState.StepOut==2){
            nodeState.StepOut="等待水或料完成";
        }else if(nodeState.StepOut==3){
            nodeState.StepOut="等待出料完成";
        }else{
            nodeState.StepOut="等待出水完成";
        }

        if(nodeState.MtRun==0){
            nodeState.MtRun="停止";
        }else if(nodeState.MtRun==1){
            nodeState.MtRun="运行";
        }else{
            nodeState.MtRun="错误";
        }

        if(nodeState.WtRun==0){
            nodeState.WtRun="停止";
        }else if(nodeState.WtRun==1){
            nodeState.WtRun="运行";
        }else{
            nodeState.WtRun="错误";
        }

        form.val("form_status",nodeState);
        if(selectedTreeNode.enable>0){
            if(selectedTreeNode.online>0){
                $("#title_online").show();
                $("#title_offline").hide();
                $("#title_disable").hide();
                $("#title_ver").show();
                $("#title_ver").html("版本号:"+nodeState.Version);
                if(selectedTreeNode.alarm>0){
                    $("#title_alarm").show();
                    $("#title_alarm").html("告警:"+nodeState.AlarmStr);
                }else{
                    $("#title_alarm").hide();
                }
            }else{
                $("#title_online").hide();
                $("#title_offline").show();
                $("#title_disable").hide();
                $("#title_ver").hide();
                $("#title_alarm").hide();
                layer.alert("当前饲喂器离线");
            }

        }else{
            $("#title_online").hide();
            $("#title_offline").hide();
            $("#title_disable").show();
            $("#title_ver").hide();
            $("#title_alarm").hide();
            layer.alert("当前饲喂器已停用");
        }
    }

    function refreshDeliverStatus(nodeState) {
        nodeState.Sn = selectedTreeNode.sn;
        
        if(nodeState.InStateBit0>0){
            nodeState.InStateBit0 = "√";
        }else{
            nodeState.InStateBit0 = "-";
        }
        if(nodeState.InStateBit1>0){
            nodeState.InStateBit1 = "√";
        }else{
            nodeState.InStateBit1 = "-";
        }
        if(nodeState.InStateBit2>0){
            nodeState.InStateBit2 = "√";
        }else{
            nodeState.InStateBit2 = "-";
        }
        if(nodeState.InStateBit3>0){
            nodeState.InStateBit3 = "√";
        }else{
            nodeState.InStateBit3 = "-";
        }
        if(nodeState.InStateBit4>0){
            nodeState.InStateBit4 = "√";
        }else{
            nodeState.InStateBit4 = "-";
        }
        if(nodeState.InStateBit5>0){
            nodeState.InStateBit5 = "√";
        }else{
            nodeState.InStateBit5 = "-";
        }

        form.val("form_status",nodeState);

        if(selectedTreeNode.enable>0){
            if(selectedTreeNode.online>0){
                $("#title_online_1").show();
                $("#title_offline_1").hide();
                $("#title_disable_1").hide();
                $("#title_ver_1").show();
                $("#title_ver_1").html("版本号:"+nodeState.Version);
                if(selectedTreeNode.alarm>0){
                    $("#title_alarm_1").show();
                    $("#title_alarm_1").html("告警:"+nodeState.AlarmStr);
                }else{
                    $("#title_alarm_1").hide();
                }
            }else{
                $("#title_online_1").hide();
                $("#title_offline_1").show();
                $("#title_disable_1").hide();
                $("#title_ver_1").hide();
                $("#title_alarm_1").hide();
                layer.alert("当前联动拉料设备离线");
            }

        }else{
            $("#title_online_1").hide();
            $("#title_offline_1").hide();
            $("#title_disable_1").show();
            $("#title_ver_1").hide();
            $("#title_alarm_1").hide();
            layer.alert("当前联动拉料设备已停用");
        }
    }
    
    function refreshBnStatus(nodeBnState){
        if(selectedTreeNode.enable>0){
            if(selectedTreeNode.online>0){
                $("#title_online_2").show();
                $("#title_offline_2").hide();
                $("#title_disable_2").hide();
                $("#title_ver_2").show();
                $("#title_ver_2").html("版本号:"+nodeBnState.Version);
                if(selectedTreeNode.alarm>0){
                    $("#title_alarm_2").show();
                    $("#title_alarm_2").html("告警:"+nodeBnState.AlarmStr);
                }else{
                    $("#title_alarm_2").hide();
                }
            }else{
                $("#title_online_2").hide();
                $("#title_offline_2").show();
                $("#title_disable_2").hide();
                $("#title_ver_2").show();
                $("#title_ver_2").html("版本号:"+nodeBnState.Version);
                if(selectedTreeNode.alarm>0){
                    $("#title_alarm_2").show();
                    $("#title_alarm_2").html("告警:"+nodeBnState.AlarmStr);
                }else{
                    $("#title_alarm_2").hide();
                }
                layer.alert("设备离线");
            }

        }else{
            $("#title_online_2").hide();
            $("#title_offline_2").hide();
            $("#title_disable_2").show();
            $("#title_ver_2").show();
            $("#title_ver_2").html("版本号:"+nodeBnState.Version);
            if(selectedTreeNode.alarm>0){
                $("#title_alarm_2").show();
                $("#title_alarm_2").html("告警:"+nodeBnState.AlarmStr);
            }else{
                $("#title_alarm_2").hide();
            }
            layer.alert("设备已停用");
        }
        
        nodeBnState.Sn = selectedTreeNode.sn;
        for(var i=0;i<2;i++){
            nodeBnState["TAutoRun"+(i+1).toString()] = nodeBnState.TAutoRun[i];
            nodeBnState["ManWater"+(i+1).toString()] = nodeBnState.ManWater[i];
            nodeBnState["WtRun"+(i+1).toString()] = nodeBnState.WtRun[i];
            nodeBnState["Gday"+(i+1).toString()] = nodeBnState.Gday[i];
            nodeBnState["StartT"+(i+1).toString()] = nodeBnState.StartT[i];
            nodeBnState["EndT"+(i+1).toString()] = nodeBnState.EndT[i];
            nodeBnState["Adval"+(i+1).toString()] = nodeBnState.Adval[i];
            nodeBnState["DayUseFeedAuto"+(i+1).toString()] = nodeBnState.DayUseFeedAuto[i];
            nodeBnState["DayUseFeedMan"+(i+1).toString()] = nodeBnState.DayUseFeedMan[i];
            nodeBnState["TimeUseFeed"+(i+1).toString()] = nodeBnState.TimeUseFeed[i];
        }

        form.val("form_status",nodeBnState);
    }

    function refreshJyStatus(nodeJyState){
        if(selectedTreeNode.enable>0){
            if(selectedTreeNode.online>0){
                $("#title_online_3").show();
                $("#title_offline_3").hide();
                $("#title_disable_3").hide();
                $("#title_ver_3").show();
                $("#title_ver_3").html("版本号:"+nodeJyState.Version);
                if(nodeJyState.AlarmStr.length>0){
                    $("#title_alarm_3").show();
                    $("#title_alarm_3").html("告警:"+nodeJyState.AlarmStr);
                }else{
                    $("#title_alarm_3").hide();
                }
            }else{
                $("#title_online_3").hide();
                $("#title_offline_3").show();
                $("#title_disable_3").hide();
                $("#title_ver_3").show();
                $("#title_ver_3").html("版本号:"+nodeJyState.Version);
                if(nodeJyState.AlarmStr.length>0){
                    $("#title_alarm_3").show();
                    $("#title_alarm_3").html("告警:"+nodeJyState.AlarmStr);
                }else{
                    $("#title_alarm_3").hide();
                }
                layer.alert("设备离线");
            }

        }else{
            $("#title_online_3").hide();
            $("#title_offline_3").hide();
            $("#title_disable_3").show();
            $("#title_ver_3").show();
            $("#title_ver_3").html("版本号:"+nodeJyState.Version);
            if(nodeJyState.AlarmStr.length>0){
                $("#title_alarm_3").show();
                $("#title_alarm_3").html("告警:"+nodeJyState.AlarmStr);
            }else{
                $("#title_alarm_3").hide();
            }
            layer.alert("设备已停用");
        }

        form.val("form_status",nodeJyState);
    }
    
    function refreshFgStatus(nodeFgState) {
        $(".lb_feed_water").html("水料比");
        if(nodeFgState.Mode=="0"){
            nodeFgState.Mode="停用";
        }else if(nodeFgState.Mode=="1"){
            nodeFgState.Mode="保育";
        }
        else if(nodeFgState.Mode=="2"){
            nodeFgState.Mode="育肥";
        }
        else if(nodeFgState.Mode=="3"){
            nodeFgState.Mode="定时";
        }


        

        if(nodeFgState.ManFeed>0){
            nodeFgState.ManFeed="运行";
        }else{
            nodeFgState.ManFeed="停止";
        }

        if(nodeFgState.ManWater>0){
            nodeFgState.ManWater="运行";
        }else{
            nodeFgState.ManWater="停止";
        }

        if(nodeFgState.TbAct>0){
            nodeFgState.TbAct="触发";
        }else{
            nodeFgState.TbAct="未触发";
        }

        if(nodeFgState.TAutoRun==0){
            nodeFgState.TAutoRun="无效";
        }else if(nodeFgState.TAutoRun==1){
            nodeFgState.TAutoRun="时段";
        }else{
            nodeFgState.TAutoRun="触碰杆";
        }

        if(nodeFgState.StepOut==0){
            nodeFgState.StepOut="预出水";
        }else if(nodeFgState.StepOut==1){
            nodeFgState.StepOut="出料出水";
        }else if(nodeFgState.StepOut==2){
            nodeFgState.StepOut="等待水或料完成";
        }else if(nodeFgState.StepOut==3){
            nodeFgState.StepOut="等待出料完成";
        }else{
            nodeFgState.StepOut="等待出水完成";
        }

        if(nodeFgState.MtRun==0){
            nodeFgState.MtRun="停止";
        }else if(nodeFgState.MtRun==1){
            nodeFgState.MtRun="运行";
        }else{
            nodeFgState.MtRun="错误";
        }

        if(nodeFgState.WtRun==0){
            nodeFgState.WtRun="停止";
        }else if(nodeFgState.WtRun==1){
            nodeFgState.WtRun="运行";
        }else{
            nodeFgState.WtRun="错误";
        }

        form.val("form_status",nodeFgState);
        if(selectedTreeNode.enable>0){
            if(selectedTreeNode.online>0){
                $("#title_online").show();
                $("#title_offline").hide();
                $("#title_disable").hide();
                $("#title_ver").show();
                $("#title_ver").html("版本号:"+nodeFgState.Version);
                if(selectedTreeNode.alarm>0){
                    $("#title_alarm").show();
                    $("#title_alarm").html("告警:"+nodeFgState.AlarmStr);
                }else{
                    $("#title_alarm").hide();
                }
            }else{
                $("#title_online").hide();
                $("#title_offline").show();
                $("#title_disable").hide();
                $("#title_ver").hide();
                $("#title_alarm").hide();
                layer.alert("设备离线");
            }

        }else{
            $("#title_online").hide();
            $("#title_offline").hide();
            $("#title_disable").show();
            $("#title_ver").hide();
            $("#title_alarm").hide();
            layer.alert("已停用");
        }
    }

    function saveNodePara(field){
        var addr = czqPara.Addr;
        var tn = selectedTreeNode.idx;
        var enable = field._enable=="on"?"1":"0";

        console.info(addr,tn,enable);

        var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
        console.info(field);
        ApplyNodePara(field,nodePara);
        console.info(nodePara);
        //console.info(time_data);
        //console.info(curve_data);
        //return ;

        layer.load(1);
        $.ajax({
            type: 'PUT',
            url: '../Api/Device/HZFGW/NodeParam',
            data: {addr:addr,tn:tn,enable:enable,params:JSON.stringify(nodePara)},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            success: function(res){
                if(res){
                    if(res.code>=0){
                        //保存成功
                        //layer.close(lay_index);
                        toastr.success(res.msg);
                    }else{
                        //layer.alert(res.msg);
                        toastr.warning(res.msg, "异常");
                    }
                }
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },
            dataType: "json"
        });
    }

    function resetNodePara(){
        var addr = czqPara.Addr;
        var tn = selectedTreeNode.idx;
        var enable = "0";

        layer.load(1);
        $.ajax({
            type: 'PUT',
            url: '../Api/Device/HZFGW/ResetNodeParam',
            data: {addr:addr,tn:tn,enable:enable},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            success: function(res){
                if(res){
                    if(res.code>=0){
                        //保存成功
                        //layer.close(lay_index);
                        toastr.success(res.msg);

                        loadPara(select_device);
                        

                    }else{
                        //layer.alert(res.msg);
                        toastr.warning(res.msg, "异常");
                    }
                }
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },
            dataType: "json"
        });
    }
    //自动推算栏位号
    function autoSetHnum(){
        console.info(select_device.default_hnum_prefix,selectedTreeNode.idx);
        var hnum = select_device.default_hnum_prefix+(selectedTreeNode.idx+1).toString().PadLeft(3, '0');
        console.info(hnum);
        $("#Hnum").val(hnum);
    }

    String.prototype.PadLeft = function (len, charStr) {
        var s = this + '';
    return new Array(len - s.length + 1).join(charStr || '') + s;
    }
    String.prototype.PadRight = function (len, charStr) {
        var s = this + '';
    return s + new Array(len - s.length + 1).join(charStr || '');
    }

    //时间表
    function showTableTime(nodePara){
        //格式化成表格数据
        var data = [
        ];

        for(var i=0;i<6;i++){
            data.push({
                Idx:(i+1),
                StartT: nodePara.StartT[i],
                EndT: nodePara.EndT[i],
                OutT: nodePara.OutT[i],
            });
        }

        table.render({
            elem: '#table_time'
            ,data:data
            //,url: "{:u('Admin/getAlarmMsgPageList')}"
            //,height: '300'
            //,method:'post'
            //,headers : {'Authorization': 'Bearer '+window.localStorage.getItem("token")}
            ,where: {}
            ,page: false
            ,limit:20
            ,title: ''
            ,even:false
            //,size: 'sm' //小尺寸的表格
            ,skin: 'nob' //无框风格
            ,cols: [[
                //{type: 'checkbox', fixed: 'left'}
                {field:'Idx', title:'序号', sort: false,width:70}
                ,{field:'StartT', title:'开始时间', sort: false,width:120}
                ,{field:'EndT', title:'结束时间', sort: false,width:120}
                ,{field:'OutT', title:'出料量(%)', sort: false,width:120}
                //,{field:'m_s', title:'主从',width:70, align:"center",sort: false}
                ,{field:'', title:'操作', width:180,templet: function(d){
                        var html='';
                        //html+='<a class="edit-permission" href="#" onclick="onEditTableClick('+d.Idx+')"><span class="layui-icon layui-icon-edit layui-text-blue"> 修改</span></a>';
                        html+="<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit\" lay-event=\"edit\">修改</a>";
                        html+="<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit\" lay-event=\"reset\">重置</a>";
                        return html;
                    }}

            ]]
            ,done: function(res, curr, count){
                for(var i=0;i<actions.length;i++){
                    $('.action-'+actions[i].action_id).removeClass("layui-hide");
                }
            }
        });
    }

    //曲线
    function showTableCurve(nodePara){
        var data=[];
        if(nodePara.Mode == EMODE_IDLE){
            //停用
        }
        else if(nodePara.Mode == EMODE_PG){
            //妊娠
            for(var i=0;i<15;i++)
            {
                data.push({No:(i+1),id:i,OutDay:nodePara.OutDay[i],OutDayType:nodePara.OutDayType[i],OutMax:nodePara.OutMax[i]});
            }
        }
        else if(nodePara.Mode == EMODE_NP){
            //空怀
            data.push({No:1,id:15,OutDay:nodePara.OutDay[15],OutDayType:nodePara.OutDayType[15],OutMax:nodePara.OutMax[15]});
        }
        else if(nodePara.Mode == EMODE_CC){
            //保育
            for(var i=0;i<10;i++)
            {
                data.push({No:(i+1),id:i+16,OutDay:nodePara.OutDay[i+16],OutDayType:nodePara.OutDayType[i+16],OutMax:nodePara.OutMax[i+16]});
            }
        }
        else if(nodePara.Mode == EMODE_FAT){
            //育肥
            for(var i=0;i<18;i++)
            {
                data.push({No:(i+1),id:i+26,OutDay:nodePara.OutDay[i+26],OutDayType:nodePara.OutDayType[i+26],OutMax:nodePara.OutMax[i+26]});
            }
        }
        else if(nodePara.Mode == EMODE_NURSE){
            //哺乳
            for(var i=0;i<10;i++)
            {
                data.push({No:(i+1),id:i+44,OutDay:nodePara.OutDay[i+44],OutDayType:nodePara.OutDayType[i+44],OutMax:nodePara.OutMax[i+44]});
            }
        }
        else if(nodePara.Mode == EMODE_BOAR){
            //公猪
            data.push({No:1,id:54,OutDay:nodePara.OutDay[54],OutDayType:nodePara.OutDayType[54],OutMax:nodePara.OutMax[54]});
        }
        table.render({
            elem: '#table_curve'
            ,data:data
            //,url: "{:u('Admin/getAlarmMsgPageList')}"
            //,height: '300'
            //,method:'post'
            //,headers : {'Authorization': 'Bearer '+window.localStorage.getItem("token")}
            ,where: {}
            ,page: false
            ,limit:20
            ,title: ''
            ,even:false
            //,size: 'sm' //小尺寸的表格
            ,skin: 'nob' //无框风格
            ,cols: [[
                //{type: 'checkbox', fixed: 'left'}
                {field:'No', title:'序号', sort: false,width:70}
                ,{field:'OutDay', title:'日龄', sort: false,width:100}
                ,{field:'OutDayType', title:'模式', sort: false,width:100,templet: function(d){
                        var html='';
                        if(d.OutDayType>0){
                            html="线性";
                        }else{
                            html="阶梯";
                        }
                        return html;
                    }}
                ,{field:'OutMax', title:'当天最大出料量(kg)', sort: false,width:180}

                ,{field:'', title:'操作', width:180,templet: function(d){
                        var html='';
                        //html+='<a class="edit-permission" href="#" onclick="onEditTableClick('+d.Idx+')"><span class="layui-icon layui-icon-edit layui-text-blue"> 修改</span></a>';
                        html+="<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit\" lay-event=\"edit\">修改</a>";
                        html+="<a class=\"layui-btn layui-btn-normal layui-btn-xs layui-hide action-edit\" lay-event=\"reset\">重置</a>";
                        return html;
                    }}

            ]]
            ,done: function(res, curr, count){
                for(var i=0;i<actions.length;i++){
                    $('.action-'+actions[i].action_id).removeClass("layui-hide");
                }
            }
        });
    }

    function treeOnClick(event, treeId, treeNode) {
        selectedTreeNode=treeNode;
        if(selectedTreeNode.type=="root"){
            initTable();

        }
        else if(selectedTreeNode.type=="farm"){
            initTable();

        }else if(selectedTreeNode.type=="house"){
            initTable();
        }
        else{
            if(selectedTreeNode.type=="HZFGW"){
                $(".para").show();
                $(".node_para").hide();
            }else{
                $(".para").hide();
                $(".node_para").show();
                select_node_idx = selectedTreeNode.idx;
                var nodePara = czqPara.NodeParas[selectedTreeNode.idx];
                var nodeEn = czqPara.NodeEn[selectedTreeNode.idx];
                

                refreshNodePara(nodePara,nodeEn);
            }
        }
    }
    function treeOnClick1(event, treeId, treeNode) {
        selectedTreeNode=treeNode;

        if(selectedTreeNode.type=="HZFGW" || selectedTreeNode.type=="DMXFGW"){
            $(".status").show();
            $(".node_status").hide();
            $(".deliver_status").hide();
        }else{
            console.info(selectedTreeNode);
            if(selectedTreeNode.type=="deliver"){
                $(".node_status").hide();
                $(".status").hide();
                $(".deliver_status").show();
                $(".bn_status").hide();
                $(".jy_status").hide();
                var nodeState = JSON.parse(JSON.stringify(czqState.NodeStates[selectedTreeNode.idx])) ;
                console.info(nodeState);
                refreshDeliverStatus(nodeState);
            }
            else if(selectedTreeNode.type=="bn"){
                $(".node_status").hide();
                $(".status").hide();
                $(".deliver_status").hide();
                $(".bn_status").show();
                $(".jy_status").hide();
                var nodeBnState = JSON.parse(JSON.stringify(czqState.NodeBnStates[selectedTreeNode.idx])) ;
                console.info(nodeBnState);
                refreshBnStatus(nodeBnState);
            }
            else if(selectedTreeNode.type=="jy"){
                $(".node_status").hide();
                $(".status").hide();
                $(".deliver_status").hide();
                $(".bn_status").hide();
                $(".jy_status").show();
                var nodeJyState = JSON.parse(JSON.stringify(czqState.NodeJyStates[selectedTreeNode.idx])) ;
                console.info(nodeJyState);
                refreshJyStatus(nodeJyState);
            }
            else if(selectedTreeNode.type=="fg"){
                $(".deliver_status").hide();
                $(".node_status").show();
                $(".status").hide();
                $(".bn_status").hide();
                $(".jy_status").hide();
                var nodeFgState = JSON.parse(JSON.stringify(czqState.NodeFgStates[selectedTreeNode.idx])) ;
                console.info(nodeFgState);
                refreshFgStatus(nodeFgState);
            }
            else if(selectedTreeNode.type=="feed"){
                $(".deliver_status").hide();
                $(".node_status").show();
                $(".status").hide();
                $(".bn_status").hide();
                $(".jy_status").hide();
                var nodeState = JSON.parse(JSON.stringify(czqState.NodeStates[selectedTreeNode.idx])) ;
                console.info(nodeState);
                refreshNodeStatus(nodeState);
            }
            
        }
    }

    //应用界面数据到终端参数
    function ApplyPara(field) {
        czqPara.Addr = field.Addr;
        czqPara.Sip = field.Sip;
        czqPara.Port = field.Port;
        czqPara.ComType = field.ComType;
        czqPara.Dhcp = field.Dhcp=="on"?"1":"0";
        czqPara.Lip = field.Lip;
        czqPara.Gw = field.Gw;
        czqPara.Msk = field.Msk;
        czqPara.Apn = field.Apn;
        czqPara.User = field.User;
        czqPara.Pass = field.Pass;
    }
    function ApplyNodePara(field,nodePara) {
        nodePara.Sn = field.Sn;
        nodePara.Gday = field.Gday;
        nodePara.Hnum = field.Hnum;
        nodePara.CalAD = field.CalAD;
        nodePara.CalADR = field.CalADR;
        nodePara.CalFeed = field.CalFeed;
        nodePara.ChargeWater = field.ChargeWater;
        nodePara.CWaterTimeGap = field.CWaterTimeGap;
        nodePara.Mode = field.Mode;
        nodePara.Son = field.Son;
        nodePara.SonBase = field.SonBase;
        nodePara.AddSon = field.AddSon;
        nodePara.Age = field.Age;
        nodePara.AddAge = field.AddAge;
        nodePara.Fit = field.Fit;
        //nodePara.AddFit = field.AddFit;
        if(nodePara.Mode==EMODE_PG){
            //妊娠
            nodePara.AddFit[0] = field._AddFit;
        }else if(nodePara.Mode==EMODE_NP){
            //空怀
            nodePara.AddFit[1] = field._AddFit;
        }else if(nodePara.Mode==EMODE_NURSE){
            //哺乳
            nodePara.AddFit[2] = field._AddFit;
        }else if(nodePara.Mode==EMODE_BOAR){
            //公猪
            nodePara.AddFit[3] = field._AddFit;
        }else{
        }
        nodePara.SonAge = field.SonAge;
        //nodePara.AddSonAge = field.AddSonAge;
        if(nodePara.Mode==EMODE_PG){
            //妊娠
            nodePara.AddSonAge[0] = field._AddSonAge;
        }else if(nodePara.Mode==EMODE_NP){
            //空怀
            nodePara.AddSonAge[1] = field._AddSonAge;
        }else if(nodePara.Mode==EMODE_NURSE){
            //哺乳
            nodePara.AddSonAge[2] = field._AddSonAge;
        }else{
        }
        //nodePara.FFeed = field.FFeed;
        //nodePara.FeedTimeGap = field.FeedTimeGap;
        if(nodePara.Mode==EMODE_CC){
            //保育
            nodePara.FFeed[0] = field._FFeed;
            nodePara.FeedTimeGap[0] = field._FeedTimeGap;
        }else if(nodePara.Mode==EMODE_FAT){
            //育肥
            nodePara.FFeed[1] = field._FFeed;
            nodePara.FeedTimeGap[1] = field._FeedTimeGap;
        }else if(nodePara.Mode==EMODE_NURSE){
            //哺乳
            nodePara.FFeed[2] = field._FFeed;
            nodePara.FeedTimeGap[2] = field._FeedTimeGap;
        }else{
        }

        if(field._EnWater){
            nodePara._EnWater = field._EnWater;
        }else{
            nodePara._EnWater = "";
        }

        nodePara.EnWater = (nodePara._EnWater=="on"?"1":"0");
        nodePara.ReverseTimes = field.ReverseTimes;
        nodePara.ReverseTurns = field.ReverseTurns;
        nodePara.ManOut = field.ManOut;
        nodePara.ManWaterOut = field.ManWaterOut;
        //nodePara.TbTotalTime = field.TbTotalTime;
        //nodePara.FeedWater = field.FeedWater;
        //nodePara.YlCheck = field.YlCheck;
        //nodePara.AutoOut = field.AutoOut;
        if(nodePara.Mode>EMODE_IDLE) {
            nodePara.TbTotalTime[nodePara.Mode - 1] = field._TbTotalTime;
            nodePara.FeedWater[nodePara.Mode - 1] = field._FeedWater;
            nodePara.YlCheck[nodePara.Mode - 1] = field._YlCheck=="on"?"1":"0";
            nodePara.AutoOut[nodePara.Mode - 1] = field._AutoOut;
        }else{
        }
        nodePara.FeedOffset = field.FeedOffset;


    }

    function search(params) {
        Table.reload({
            where: params
            ,page: {
                curr: 1 //重新从第 1 页开始
            }
        });
    }

    function onAllocate(item) {
        console.info(item);
        /*var userids = '';
        for(var i=0;i<allData.length;i++){
            if(allData[i].id==id){
                userids = allData[i].userids;
                break;
            }
        }*/
        form.val('form_allocate',{id:item.id,userids:item.userids,device_addr:item.device_addr});

        selectUser = xmSelect.render({
            el: '#users',
            tips: '选择操作',
            filterable: true,
            direction: 'auto',
            theme: {
                color: '#4958b9'
            },
            prop: {
                name: 'name',
                value: 'userid',
            },
            data: users
        });
        var arr=[];
        if(item.userids.length>0){
            arr = item.userids.split(",");
        }
        selectUser.setValue(arr);



        layer.open({
            //area: 'auto',
            area:['400px','450px'],
            offset: '10%',
            shade: 0.5,
            shadeClose: true,
            type: 1,
            title: '分配', //不显示标题
            content: $('#form_allocate'), //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
            maxmin: false,
            btn: ['确定', '取消'],
            yes: function(index, layero){
                //点击确认触发 iframe 内容中的按钮提交
                lay_index=index;
                var submit = layero.contents().find("#btn_allocate");
                submit.click();
            }
        });
    }

    function getFont(treeId, node) {
        return node.font ? node.font : {};
    }

    function loadTree() {
        //layer.load(1);
        /*
        $.ajax({
            type: 'GET',
            url: '../Api/Topo',
            data: {},
            beforeSend: function(request) {
                request.setRequestHeader("Authorization", 'Bearer '+window.localStorage.getItem("token"));
            },
            dataType: "json",
            success: function (data) {
                //var data=data.data;
                var nodes=setDataIcon(data.data);
                
                zTree = $.fn.zTree.init($("#treeDemo"), tree_setting, nodes);
                var nodes = zTree.getNodesByParam("type", "root", null);
                console.info(nodes);
                if(nodes.length>0){
                    const node = nodes[0];
                    console.info(node);
                    zTree.selectNode(node);
                    setTimeout(function(){zTree.setting.callback.onClick(null,null,node);},500);

                }

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.msg('加载信息失败');
            },
            complete: function(XMLHttpRequest, textStatus) {
                layer.closeAll('loading');
            },
        });
        */

        zTree = $.fn.zTree.init($("#treeDemo"), tree_setting);
    }

    function validate_int(min,max,event){
        console.info(event);
        var val = event.target.value;
        var name = event.target.name;
        if (parseFloat(val) < min || parseFloat(val) > max) {
            toastr.error("必须在"+min+"-"+max+"范围");
            val = val.substring(0, val.length - 1);
            $(event.target).css("background","#884311");
            
            setTimeout(()=>{$(event.target).val(val);},50)
        }else{
            $(event.target).css("background","#ffffff");
        }
    }
    
    //设置图标
    function setDataIcon(data){

        for(let i=0; i<data.length; i++){
            var node=data[i];

            node['font']={'color':'#333'};
            if(node.type=='group'){
                //node.name = "";
                node["icon"]="../plugins/zTree/css/metroStyle/img/net.png";
                //node.isParent=true;
                node.open = true;
            }
            else if(node.type=='area'){
                node["icon"]="../plugins/zTree/css/metroStyle/img/area.png";
                //node.isParent=true;
                node.open = true;
            }
            else if(node.type=='farm'){
                node["icon"]="../plugins/zTree/css/metroStyle/img/location.png";
                node.isParent=true;
            }else if(node.type=='house'){
                node["icon"]="../plugins/zTree/css/metroStyle/img/house.png";
                node.isParent=false;
                if(node.device_online)
                {
                    node['font']={'color':'#3c7cff'};
                }else{
                    node['font']={'color':'#A3A8B6'};
                }
                //node['font']={'color':'#4958b9','font-weight':"bold"};
            }
            else if(node.type=='HZFGW') {
                node["icon"] = "../plugins/zTree/css/metroStyle/img/gw.png";
                node.isParent=false;
                node.open=true;
            }
            else if(node.type=='DMXFGW') {
                node["icon"] = "../plugins/zTree/css/metroStyle/img/gw.png";
                node.isParent=false;
                node.open=true;
            }
            else if(node.type=='hnum') {
                node["icon"] = "../plugins/zTree/css/metroStyle/img/farm.png";
                //node.isParent=false;
                //node.open=false;
                //node["isHidden"] = true;
            }
            else if(node.type=='feed'){
                if(node.enable>0){
                    if(node.online>0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#3c7cff'};
                        if(node.alarm>0){
                            node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                            node['font']={'color':'#f29114'};
                        }
                    }else if(node.online==0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node_offline.png";
                        node['font']={'color':'#333'};
                    }else if(node.online==-1){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#fff'};
                    }
                }else{
                    node["icon"]="../plugins/zTree/css/metroStyle/img/no.png";
                    node['font']={'color':'#333'};
                }

                node.isParent=false;
            }
            else if(node.type=='deliver'){
                if(node.enable>0){
                    if(node.online>0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#3c7cff'};
                        if(node.alarm>0){
                            node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                            node['font']={'color':'#f29114'};
                        }
                    }else if(node.online==0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node_offline.png";
                        node['font']={'color':'#333'};
                    }else if(node.online==-1){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#fff'};
                    }
                }else{
                    node["icon"]="../plugins/zTree/css/metroStyle/img/no.png";
                    node['font']={'color':'#333'};
                }

                node.isParent=false;
            }
            else if(node.type=='bn' || node.type=='jy' || node.type=='fg'){
                if(node.enable>0){
                    if(node.online>0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#3c7cff'};
                        if(node.alarm>0){
                            node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                            node['font']={'color':'#f29114'};
                        }
                    }else if(node.online==0){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node_offline.png";
                        node['font']={'color':'#333'};
                    }else if(node.online==-1){
                        node["icon"]="../plugins/zTree/css/metroStyle/img/node.png";
                        node['font']={'color':'#fff'};
                    }
                }else{
                    node["icon"]="../plugins/zTree/css/metroStyle/img/no.png";
                    node['font']={'color':'#333'};
                }

                node.isParent=false;
            }
            if(node['children']){
                var data1=node.children;
                setDataIcon(data1);
            }
        }
        return data;
    }

    $(window).resize(function () {
        //console.info('resize')
        resize();
    });
    function resize() {
        var h = $('#wd_param').height();
        $("#tree1").slimScroll({
            height: h-25,
            size: '4px', //组件宽度
            color: '#eee', //滚动条颜色
            position: 'right', //组件位置：left/right
            distance: '0px', //组件与侧边之间的距离
            start: 'top', //默认滚动位置：top/bottom
            opacity: .4, //滚动条透明度
            alwaysVisible: true, //是否 始终显示组件
            disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
            railVisible: true, //是否 显示轨道
            railColor: '#333', //轨道颜色
            railOpacity: .2, //轨道透明度
            railDraggable: true, //是否 滚动条可拖动
            railClass: 'slimScrollRail', //轨道div类名
            barClass: 'slimScrollBar', //滚动条div类名
            wrapperClass: 'slimScrollDiv', //外包div类名
            allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
            wheelStep: 10, //滚轮滚动量
            touchScrollStep: 200, //滚动量当用户使用手势
            borderRadius: '7px', //滚动条圆角
            railBorderRadius: '7px' //轨道圆角
        });

        $(".content-scroll").slimScroll({
            height: h-90,
            size: '4px', //组件宽度
            color: '#eee', //滚动条颜色
            position: 'right', //组件位置：left/right
            distance: '0px', //组件与侧边之间的距离
            start: 'top', //默认滚动位置：top/bottom
            opacity: .4, //滚动条透明度
            alwaysVisible: true, //是否 始终显示组件
            disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
            railVisible: true, //是否 显示轨道
            railColor: '#333', //轨道颜色
            railOpacity: .2, //轨道透明度
            railDraggable: true, //是否 滚动条可拖动
            railClass: 'slimScrollRail', //轨道div类名
            barClass: 'slimScrollBar', //滚动条div类名
            wrapperClass: 'slimScrollDiv', //外包div类名
            allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
            wheelStep: 10, //滚轮滚动量
            touchScrollStep: 200, //滚动量当用户使用手势
            borderRadius: '7px', //滚动条圆角
            railBorderRadius: '7px' //轨道圆角
        });

        var h = $('#form_status').height();

        $("#tree2").slimScroll({
            height: h-25,
            size: '4px', //组件宽度
            color: '#eee', //滚动条颜色
            position: 'right', //组件位置：left/right
            distance: '0px', //组件与侧边之间的距离
            start: 'top', //默认滚动位置：top/bottom
            opacity: .4, //滚动条透明度
            alwaysVisible: true, //是否 始终显示组件
            disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
            railVisible: true, //是否 显示轨道
            railColor: '#333', //轨道颜色
            railOpacity: .2, //轨道透明度
            railDraggable: true, //是否 滚动条可拖动
            railClass: 'slimScrollRail', //轨道div类名
            barClass: 'slimScrollBar', //滚动条div类名
            wrapperClass: 'slimScrollDiv', //外包div类名
            allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
            wheelStep: 10, //滚轮滚动量
            touchScrollStep: 200, //滚动量当用户使用手势
            borderRadius: '7px', //滚动条圆角
            railBorderRadius: '7px' //轨道圆角
        });
        $(".content-scroll1").slimScroll({
            height: h-50,
            size: '4px', //组件宽度
            color: '#eee', //滚动条颜色
            position: 'right', //组件位置：left/right
            distance: '0px', //组件与侧边之间的距离
            start: 'top', //默认滚动位置：top/bottom
            opacity: .4, //滚动条透明度
            alwaysVisible: true, //是否 始终显示组件
            disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
            railVisible: true, //是否 显示轨道
            railColor: '#333', //轨道颜色
            railOpacity: .2, //轨道透明度
            railDraggable: true, //是否 滚动条可拖动
            railClass: 'slimScrollRail', //轨道div类名
            barClass: 'slimScrollBar', //滚动条div类名
            wrapperClass: 'slimScrollDiv', //外包div类名
            allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
            wheelStep: 10, //滚轮滚动量
            touchScrollStep: 200, //滚动量当用户使用手势
            borderRadius: '7px', //滚动条圆角
            railBorderRadius: '7px' //轨道圆角
        });

        $(".tree-div").slimScroll({
            height: $(window).height()-10,
            size: '4px', //组件宽度
            color: '#eee', //滚动条颜色
            position: 'right', //组件位置：left/right
            distance: '0px', //组件与侧边之间的距离
            start: 'top', //默认滚动位置：top/bottom
            opacity: .4, //滚动条透明度
            alwaysVisible: true, //是否 始终显示组件
            disableFadeOut: false, //是否 鼠标经过可滚动区域时显示组件，离开时隐藏组件
            railVisible: true, //是否 显示轨道
            railColor: '#333', //轨道颜色
            railOpacity: .2, //轨道透明度
            railDraggable: true, //是否 滚动条可拖动
            railClass: 'slimScrollRail', //轨道div类名
            barClass: 'slimScrollBar', //滚动条div类名
            wrapperClass: 'slimScrollDiv', //外包div类名
            allowPageScroll: true, //是否 使用滚轮到达顶端/底端时，滚动窗口
            wheelStep: 10, //滚轮滚动量
            touchScrollStep: 200, //滚动量当用户使用手势
            borderRadius: '7px', //滚动条圆角
            railBorderRadius: '7px' //轨道圆角
        });
        //$('.tree-div').height($(window).height()-10);
    }

    function formatminutes(date){
        $($(".laydate-time-list li ol")[2]).find("li").remove(); //清空秒
    }
</script>
<script src="../js/check_screen.js?v=${.Config.basic.version}"></script>

</body>

<form class="layui-form " lay-filter="form" id="form" style="padding: 20px 30px 0 0;display:none;">
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label">id</label>
        <div class="layui-input-block">
            <input type="text" name="id" lay-verify="" lay-verType="tips" placeholder="" autocomplete="off" class="layui-input" disabled>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">设备类型</label>
        <div class="layui-input-block">
            <select name="device_type" lay-filter="device_type" lay-verify="required"  lay-verType="tips" lay-search="">
                <option value="" ></option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">网关SN</label>
        <div class="layui-input-block">
            <input type="text" name="device_addr" lay-verify="number" lay-verType="tips" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="remark" lay-verify=""  lay-verType="tips" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>



    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_ok" id="btn_ok" value="保存">
        <input type="button" lay-submit lay-filter="btn_cancel" id="btn_cancel" value="取消">
    </div>
</form>

<form class="layui-form" lay-filter="form_update" id="form_update" style="padding: 20px 30px 0 0;display:none;">

    <div class="layui-form-item layui-hide">
        <input type="text" name="batch" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
    </div>
    <div class="layui-form-item layui-hide">
        <input type="text" name="addr" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
    </div>

    <div class="layui-form-item layui-hide">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="text" name="device_type" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">固件</label>
        <div class="layui-input-block">
            <select name="id" lay-verify="required" style="width: 100%" >
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_update" id="btn_update" value="确认">
    </div>

</form>

<form class="layui-form" lay-filter="form_update_node" id="form_update_node" style="padding: 20px 30px 0 0;display:none;">
    <div class="layui-form-item layui-hide">
        <input type="text" name="batch" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
    </div>
    <div class="layui-form-item layui-hide">
        <input type="text" name="addr" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
    </div>
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="text" name="device_type" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
        </div>
    </div>

    <div class="layui-form-item saddr" >
        <label class="layui-form-label">饲喂器SN</label>
        <div class="layui-input-block">
            <input type="text" name="saddr" lay-verify="" lay-verType="tips" placeholder="不填写则升级全部" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">固件</label>
        <div class="layui-input-block">
            <select name="id" lay-verify="required" style="width: 100%" >
            </select>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_update_node" id="btn_update_node" value="确认">
    </div>

</form>

<div  id="wd_param" style="display:none;height: 100%;">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-md3">
            <div class="layui-card">

                <div style="padding-top: 10px;">
                    <div class="scroll" >
                        <ul id="tree1" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-md9">


            <form class="para layui-form" id="form_param" lay-filter="form_param">
                <div class="content-scroll" style="padding: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">终端地址</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="Addr" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">通信模式</label>
                            <div class="layui-input-inline">
                                <!--<input type="checkbox" name="ComType" checked="" lay-skin="switch" lay-text="开启|关闭" >-->
                                <select  name="ComType" lay-filter="ComType" lay-verify="required" lay-search=""  >
                                    <option value="0">以太网</option>
                                    <option value="1">移动</option>
                                    <option value="2">联通</option>
                                    <option value="3">电信</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">服务器IP</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Sip" lay-verify="verify_ip" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">服务器端口</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Port" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">终端地址</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Gw" lay-verify="verify_ip" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">子网掩码</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Msk" lay-verify="verify_ip" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">自动分配地址</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="Dhcp" checked="" lay-skin="switch" lay-text="自动|手动" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">本地IP</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Lip" lay-verify="verify_ip" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">APN</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Apn" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">APN用户名</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="User" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">APN密码</label>
                            <div class="layui-input-inline">
                                <input type="text" placeholder="" name="Pass" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="btn_save_param" id="btn_save_param" value="">
                </div>
            </form>

            <form  class="layui-form" id="form_node_param" lay-filter="form_node_param">
                <div class="node_para layui-tab layui-tab-brief"  style="display: none;">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本参数</li>
                        <li>时间表</li>
                        <li>曲线</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">

                            <div class="content-scroll">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">是否启用</label>
                                        <div class="layui-input-inline">
                                            <input type="checkbox"  checked="" lay-skin="switch" lay-text="启用|关闭" name="_enable">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">SN序列号</label>
                                        <div class="layui-input-inline">
                                            <input type="text"  placeholder="10位SN序列号" name="Sn" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">栏位编号</label>
                                        <div class="layui-input-inline">
                                            <input type="text" id="Hnum" placeholder="AXXX" name="Hnum" lay-verify="required" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">

                                        <div class="">
                                            <button type="button" onclick="autoSetHnum();" class="layui-btn layui-btn-sm layui-btn-normal" lay-submit="" lay-filter="">自动填写</button>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">日龄</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="Gday" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">模式</label>
                                        <div class="layui-input-inline">
                                            <select  name="Mode" lay-filter="Mode" lay-verify="required" lay-search=""  >
                                                <option value="0">停用</option>
                                                <option value="1">妊娠</option>
                                                <option value="2">空怀</option>
                                                <option value="3">保育</option>
                                                <option value="4">育肥</option>
                                                <option value="5">哺乳</option>
                                                <option value="6">公猪</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">有余料AD值</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="CalAD" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">无余料AD值</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="CalADR" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">补水量(ml)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="ChargeWater" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">补水间隔(分)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="CWaterTimeGap" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">反转次数</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="1-10" name="ReverseTimes" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">反转圈数</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="1.0-10.0" name="ReverseTurns" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">手动出料(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" @input="validate_int(0,500,event)" placeholder="≤500" name="ManOut" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">手动出水(ml)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" @input="validate_int(0,1000,event)" placeholder="≤1000" name="ManWaterOut" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">触碰杆检测时长(秒) <i class="layui-icon layui-icon-tips layui-text-white layui-text-sm" lay-tips="设置为0则不启用触碰杆,非0则启用" lay-offset="0"></i></label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="0-255" name="_TbTotalTime" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">料水比</label>
                                        <div class="layui-input-inline">
                                            <select  name="_FeedWater" lay-filter="_FeedWater" lay-verify="required" lay-search=""  >
                                                <option value="0">不出水</option>
                                                <option value="1">1:1</option>
                                                <option value="2">1:2</option>
                                                <option value="3">1:3</option>
                                                <option value="4">1:4</option>
                                                <option value="5">1:5</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">余料检测</label>
                                        <div class="layui-input-inline">
                                            <input type="checkbox"  checked="" lay-skin="switch" lay-text="开启|关闭" name="_YlCheck">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">单次出料量(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="_AutoOut" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline div_Son">
                                        <label class="layui-form-label-lg">带仔数</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="0-20" name="Son" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                    <div class="layui-inline div_SonBase">
                                        <label class="layui-form-label-lg">带仔基数</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="0-20" name="SonBase" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline div_AddSon">
                                        <label class="layui-form-label-lg">哺乳带仔数增重(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="AddSon" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">10圈出料数(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="CalFeed" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline div_Age">
                                        <label class="layui-form-label-lg">公猪年龄 </label>
                                        <div class="layui-input-inline">
                                            <!-- <input type="text" placeholder="0-8" name="Age" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input"> -->
                                            <select  name="Age" lay-filter="Age" lay-verify="number" lay-verType="tips" lay-search=""  >
                                                <option value="0">阶段1</option>
                                                <option value="1">阶段2</option>
                                                <option value="2">阶段3</option>
                                                <option value="3">阶段4</option>
                                                <option value="4">阶段5</option>
                                                <option value="5">阶段6</option>
                                                <option value="6">阶段7</option>
                                                <option value="7">阶段8</option>
                                                <option value="8">阶段9</option>
                                            </select>
                                            
                                        </div>
                                    </div>
                                    <div class="layui-inline div_AddAge">
                                        <label class="layui-form-label-lg">公猪年龄附加(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="AddAge" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">体况 <i class="layui-icon layui-icon-tips layui-text-white layui-text-sm" lay-tips="下料会根据体况附加或减少" lay-offset="0"></i></label>
                                        <div class="layui-input-inline">
                                            <!-- <input type="text" placeholder="0-4" name="Fit" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input"> -->
                                            <select  name="Fit" lay-filter="Fit" lay-verify="number" lay-verType="tips" lay-search=""  >
                                                <option value="0">较瘦</option>
                                                <option value="1">偏瘦</option>
                                                <option value="2">正常</option>
                                                <option value="3">偏胖</option>
                                                <option value="4">较胖</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline AddFit">
                                        <label class="layui-form-label-lg">体况附加(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="_AddFit" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline div_SonAge">
                                        <label class="layui-form-label-lg">胎龄</label>
                                        <div class="layui-input-inline">
                                            <!--<input type="checkbox"  checked="" lay-skin="switch" lay-text="头胎|经产" name="SonAge">-->
                                            <select  name="SonAge" lay-filter="SonAge" lay-verify="required" lay-search=""  >
                                                <option value="0">头胎</option>
                                                <option value="1">经产</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline AddSonAge">
                                        <label class="layui-form-label-lg">胎龄附加(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="_AddSonAge" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline FFeed">
                                        <label class="layui-form-label-lg">引食量(g)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="0-1" name="_FFeed" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline FeedTimeGap">
                                        <label class="layui-form-label-lg">喂料时间间隔(秒)</label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="_FeedTimeGap" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">

                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">水阀</label>
                                        <div class="layui-input-inline">
                                            <input type="checkbox"  checked="" lay-skin="switch" lay-text="启用|禁用" name="_EnWater">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">增加减少饲喂量 <i class="layui-icon layui-icon-tips layui-text-white layui-text-sm" lay-tips="饲喂量偏移量，可以为正负值" lay-offset="0"></i></label>
                                        <div class="layui-input-inline">
                                            <input type="text" placeholder="" name="FeedOffset" lay-verify="number" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                        <label class="layui-form-label">x100g</label>
                                    </div>
                                </div>



                            </div>

                        </div>

                        <div class="layui-tab-item ">
                            <div class="content-scroll">
                                <!--<blockquote class="layui-elem-quote"> 时间表</blockquote>-->
                                <table class="layui-hide" id="table_time" lay-filter="table_time"></table>
                            </div>
                        </div>

                        <div class="layui-tab-item ">
                            <div class="content-scroll">
                                <!--<blockquote class="layui-elem-quote"> 曲线表</blockquote>-->
                                <table class="layui-hide" id="table_curve" lay-filter="table_curve"></table>
                            </div>
                        </div>

                    </div>
                </div>

                <div class="layui-form-item layui-hide">
                    <input type="button" lay-submit lay-filter="btn_save_node_param" id="btn_save_node_param" value="">
                </div>
            </form>


        </div>
    </div>


</div>

<form class="layui-form" id="form_status" lay-filter="form_status" style="display:none;height: 100%;">
    <div class="layui-row layui-col-space1">
        <div class="layui-col-md4">
            <div class="layui-card">

                <div style="padding-top: 10px;">
                    <div class=" scroll" >
                        <ul id="tree2" class="ztree"></ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-col-md8">
            <div class="status">
                <div style="margin: 5px;border-bottom: 1px solid #7ca8bf;padding: 5px;">
                    <span id="title_version" class="layui-badge layui-bg-black"></span>
                </div>
                <div class="content-scroll1" style="padding: 10px;">


                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">信号强度</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="Rssi" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">通讯模式</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="ComType" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">经度</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="Lng" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">纬度</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="Lng" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">ICCID</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly placeholder="" name="Iccid" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>


                    </div>
                </div>
            </div>

            <div class="node_status" style="display: none;">
                <div style="margin: 5px;border-bottom: 1px solid #7ca8bf;padding: 5px;">

                    <span id="title_online" class="layui-badge layui-bg-green">在线</span>
                    <span id="title_offline" class="layui-badge layui-bg-black">离线</span>
                    <span id="title_disable" class="layui-badge layui-bg-black">停用</span>
                    <span id="title_ver" class="layui-badge layui-bg-black"></span>
                    <span id="title_alarm" class="layui-badge layui-bg-red"></span>
                </div>
                <div class="content-scroll1" style="padding: 10px;">



                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">日龄</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Gday" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">模式</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Mode" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">手动出料状态</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="ManFeed" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">

                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">手动出水状态</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="ManWater" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">

                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg lb_feed_water">料水比</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="FeedWater" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">接入</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InState" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">触碰杆触发动作</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="TbAct" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <!-- <div class="layui-inline">
                            <label class="layui-form-label-lg">触碰杆触碰次数</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="TbTimes" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div> -->
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">时间出料状态</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="TAutoRun" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">喂料过程</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="StepOut" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">出料状态</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="MtRun" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">出水状态</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="WtRun" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当天最大喂料量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="MaxFeed" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">余料检测AD值</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Adval" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>


                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当前开始时段</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="StartT" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当前结束时段</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="EndT" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">时段下料总量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="OutT" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">该时段已经下料量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="TimeUseFeed" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当天自动消总耗水</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DayUseWaterAuto" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当天自动消总料量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DayUseFeedAuto" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当天手动总耗水</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DayUseWaterMan" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当天手动总料量</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DayUseFeedMan" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                </div>

            </div>

            <div class="deliver_status" style="display: none;">
                <div style="margin: 5px;border-bottom: 1px solid #7ca8bf;padding: 5px;">

                    <span id="title_online_1" class="layui-badge layui-bg-green">在线</span>
                    <span id="title_offline_1" class="layui-badge layui-bg-black">离线</span>
                    <span id="title_disable_1" class="layui-badge layui-bg-black">停用</span>
                    <span id="title_ver_1" class="layui-badge layui-bg-black"></span>
                    <span id="title_alarm_1" class="layui-badge layui-bg-red"></span>
                </div>
                <div class="content-scroll1" style="padding: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">SN</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Sn" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">运行</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit0" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">料满</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">报警</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">链盘门</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit3" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">堵料</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit4" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">急停</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="InStateBit5" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="bn_status" style="display: none;">
                <div style="margin: 5px;border-bottom: 1px solid #7ca8bf;padding: 5px;">

                    <span id="title_online_2" class="layui-badge layui-bg-green">在线</span>
                    <span id="title_offline_2" class="layui-badge layui-bg-black">离线</span>
                    <span id="title_disable_2" class="layui-badge layui-bg-black">停用</span>
                    <span id="title_ver_2" class="layui-badge layui-bg-black"></span>
                    <span id="title_alarm_2" class="layui-badge layui-bg-red"></span>
                </div>
                <div class="content-scroll1" style="padding: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">SN</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Sn" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当前时间</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DateTime" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>

                    <div class=" layui-tab layui-tab-brief"  style="">
                        <ul class="layui-tab-title">
                            <li class="layui-this">组1</li>
                            <li>组2</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">出奶状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="WtRun1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">时间出料状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="TAutoRun1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">手动出料状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="ManWater1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">日龄</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="Gday1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">天自动料量</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="DayUseFeedAuto1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">天手动料量</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="DayUseFeedMan1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">当前开始时段</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="StartT1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">当前结束时段</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="EndT1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">AD值</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="Adval1" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-tab-item ">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">出奶状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="WtRun2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">时间出料状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="TAutoRun2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">手动出料状态</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="ManWater2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">日龄</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="Gday2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">天自动料量</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="DayUseFeedAuto2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">天手动料量</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="DayUseFeedMan2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>

                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">当前开始时段</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="StartT2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">当前结束时段</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="EndT2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label-lg">AD值</label>
                                        <div class="layui-input-inline">
                                            <input type="text" readonly  name="Adval2" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                </div>
            </div>

            <div class="jy_status" style="display: none;">
                <div style="margin: 5px;border-bottom: 1px solid #7ca8bf;padding: 5px;">

                    <span id="title_online_3" class="layui-badge layui-bg-green">在线</span>
                    <span id="title_offline_3" class="layui-badge layui-bg-black">离线</span>
                    <span id="title_disable_3" class="layui-badge layui-bg-black">停用</span>
                    <span id="title_ver_3" class="layui-badge layui-bg-black"></span>
                    <span id="title_alarm_3" class="layui-badge layui-bg-red"></span>
                </div>
                <div class="content-scroll1" style="padding: 10px;">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">SN</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Sn" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">当前时间</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="DateTime" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">模式</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="Mode" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">蓝牙</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="BtOn" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">进水运行</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="WtRun" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">出药运行</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="MedRun" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label-lg">药筒药量(L)</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="MlMED" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label-lg">步骤</label>
                            <div class="layui-input-inline">
                                <input type="text" readonly  name="LgStep" lay-verify="" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>

<form class="layui-form" lay-filter="form_time" id="form_time" style="padding: 20px 30px 0 0;display:none;">
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="text" name="Idx" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">起始时间</label>
        <div class="layui-input-block">
            <input type="text" name="StartT" id="StartT" lay-verify="required" lay-verType="tips" placeholder="起始时间" autocomplete="off" class="layui-input" style="width: 100%;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input type="text" name="EndT" id="EndT" lay-verify="required" lay-verType="tips" placeholder="结束时间" autocomplete="off" class="layui-input" style="width: 100%;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出料量(%)</label>
        <div class="layui-input-block">
            <input  type="text" name="OutT" lay-verify="percent" lay-verType="tips" placeholder="%" autocomplete="off" class="layui-input" style="width: 100%;">
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_time_edit_ok" id="btn_time_edit_ok" value="确认">
        <input type="button" lay-submit lay-filter="btn_cancel" id="btn_cancel" value="取消">
    </div>

</form>


<form class="layui-form" lay-filter="form_curve" id="form_curve" style="padding: 20px 30px 0 0;display:none;">
    <div class="layui-form-item layui-hide">
        <label class="layui-form-label"></label>
        <div class="layui-input-block">
            <input type="text" name="id" lay-verify="required" placeholder="" autocomplete="off" class="layui-input" style="width: 100%">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">模式</label>
        <div class="layui-input-block">
            <select  name="OutDayType" lay-filter="OutDayType" lay-verify="required" lay-search="" style="width: 100%;" >
                <option value="0">阶梯</option>
                <option value="1">线性</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">日龄</label>
        <div class="layui-input-block">
            <input type="text" name="OutDay" id="OutDay" lay-verify="number" lay-verType="tips" placeholder="起始时间" autocomplete="off" class="layui-input" style="width: 100%;">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">出料量(kg)</label>
        <div class="layui-input-block">
            <input type="text" name="OutMax" id="OutMax" lay-verify="number" lay-verType="tips" placeholder="结束时间" autocomplete="off" class="layui-input" style="width: 100%;">
        </div>
    </div>


    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_curve_edit_ok" id="btn_curve_edit_ok" value="确认">
        <input type="button" lay-submit lay-filter="btn_cancel" id="btn_cancel" value="取消">
    </div>

</form>

<form class="layui-form" lay-filter="form_allocate" id="form_allocate" style="padding: 20px 30px 0 0;display:none;">
    <input class="layui-hide" type="text" name="id" lay-verify="">
    <input class="layui-hide" type="text" name="device_addr" lay-verify="">
    <div class="layui-form-item">
        <label class="layui-form-label">分配用户</label>
        <div class="layui-input-inline" style="width: 200px;">
            <div id="users" class="demo-transfer"></div>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="btn_allocate" id="btn_allocate" value="确认">
        <input type="button" lay-submit lay-filter="btn_cancel" id="btn_cancel" value="取消">
    </div>
</form>

</html>